unit UCutFigure_JPG;
//JPG 切图 interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls,Math, jpeg
; //向左旋转X度
procedure Rotate(Srcbmp, DestBmp: TBitmap; dbTheta: Double);
//毫米单位转换为英寸单位
function MmToInch(Length: Extended): Extended;
//英寸单位转换为毫米单位
function InchToMm(Length: Extended): Extended;
function CutFigure_JPG(图片文件名:string;旋转角度:integer;切边_上,切边_下,切边_左,切边_右:real;缩放_宽,缩放_高:real):Integer;
implementation function CutFigure_JPG(图片文件名:string;旋转角度:integer;切边_上,切边_下,切边_左,切边_右:real;缩放_宽,缩放_高:real):Integer;
var
JpgSrc,JpgDest : TJpegImage;
BmpSrc, BmpDest: TBitmap;
F_上,F_下,F_左,F_右,F_长,F_宽:integer;//切边值
F_缩放比率:real;
F_处理状态:boolean;
begin
//文件名,含全路径
if not FileExists(图片文件名) then exit;//文件不存在则退出 JpgSrc := TJpegImage.Create;
JpgDest:=TJpegImage.Create ;
BmpSrc:=TBitmap.Create;
BmpDest:=TBitmap.Create ; JpgSrc.LoadFromFile(图片文件名);//加载文件
BmpSrc.Assign(JpgSrc);
F_处理状态:=False;//未处理过
if 旋转角度> then
begin
Rotate(BmpSrc, BmpDest,旋转角度); //由于函数是左向旋转,所以这里角度设置为270。
F_处理状态:=true;
end; if (切边_上>) or (切边_下>) or (切边_左>) or (切边_右>) then
begin
//需要切边
if F_处理状态=true then
BmpSrc.Assign(BmpDest);
//切边传进来的参数,为cm
if 切边_上< then 切边_上:=;
if 切边_下< then 切边_下:=;
if 切边_左< then 切边_左:=;
if 切边_右< then 切边_右:=; F_上:=Round(MmToInch(切边_上)**);
F_下:=Round(MmToInch(切边_下)**);
F_左:=Round(MmToInch(切边_左)**);
F_右:=Round(MmToInch(切边_右)**); if (F_上+F_下<BmpSrc.Height) and (F_左+F_右>=BmpSrc.Width ) then
begin //值超范围,不处理
BmpDest.Height:=BmpSrc.Height-(F_上+F_下);
BmpDest.Width:=BmpSrc.Width-(F_左+F_右);
SetStretchBltMode(BmpDest.Canvas.Handle,HALFTONE);//设置指位图拉伸模式
stretchblt(BmpDest.Canvas.Handle,,,BmpDest.Width,BmpDest.Height,BmpSrc.Canvas.Handle,F_左,F_上,BmpDest.Width,BmpDest.Height,srccopy); //从源矩形中复制一个位图到目标矩形并适当压缩
F_处理状态:=true;
end ; end; if (缩放_高>) or (缩放_宽>) then
begin
//需要缩放
if F_处理状态=true then
BmpSrc.Assign(BmpDest); F_长:=Round(MmToInch(缩放_高)**);
F_宽:=Round(MmToInch(缩放_宽)**); if (F_长>) and (F_宽>) and (BmpSrc.Height>F_长) and (BmpSrc.Width >F_宽) then
begin
//如果都超过,则等比缩小到其中较大的一个值等于目标值
if (F_长/BmpSrc.Height)>(F_宽/BmpSrc.Width) then
begin
F_缩放比率:=F_宽/BmpSrc.Width;
end
else
begin
F_缩放比率:=F_长/BmpSrc.Height;
end;
end
else
if (F_长>) and (BmpSrc.Height>F_长) then
begin
F_缩放比率:=F_长/BmpSrc.Height;
end
else
if (F_宽>) and (BmpSrc.Width >F_宽) then
begin
F_缩放比率:=F_宽/BmpSrc.Width;
end
else
begin
F_缩放比率:=-;//如果没取到值,或原图已经小于设定值则不处理
end; if F_缩放比率> then
begin
BmpDest.Height:=Round(BmpSrc.Height*F_缩放比率);
BmpDest.Width:=Round(BmpSrc.Width *F_缩放比率); SetStretchBltMode(BmpDest.Canvas.Handle,HALFTONE);//设置指位图拉伸模式
stretchblt(BmpDest.Canvas.Handle,,,BmpDest.Width,BmpDest.Height,BmpSrc.Canvas.Handle,,,BmpSrc.Width,BmpSrc.Height,srccopy); //从源矩形中复制一个位图到目标矩形并适当压缩
F_处理状态:=true;
end;
end; if F_处理状态=true then
begin
//处理后,保存图片
JpgDest.CompressionQuality := ;
JpgDest.Assign(BmpDest);
JpgDest.SaveToFile(图片文件名);
end; JpgSrc.Free;
JpgDest.free;
BmpSrc.Free;
BmpDest.Free; end; procedure Rotate(Srcbmp, DestBmp: TBitmap; dbTheta: Double);//此过程是网上找的,不记得原博文地址了,抱歉
var
ptOrgCenter, ptTarCenter, ptc: TPoint;
pta: array[..] of TPoint;
ba: array[..] of integer;
i: integer;
function RotateXY(dbTheda: double; p1: TPoint): TPoint;
var
dbA: double;
_cosA, _sinA, _dbLastT: double;
begin
_dbLastT := -99999.999;
_cosA :=0.0;
_sinA :=0.0; if dbTheda <> _dbLastT then
begin
dbA := dbTheda * Pi / ;
_sinA := sin(dbA);
_cosA := cos(dbA);
_dbLastT := dbTheda;
end; Result.x := round(p1.x * _cosA + p1.y * _sinA);
Result.y := round(-p1.x * _sinA + p1.y * _cosA);
end;
begin
ptOrgCenter.x := Srcbmp.Width div ;
ptOrgCenter.y := Srcbmp.Height div ; pta[] := RotateXY(dbTheta,Point(, ));
//这里不知道原来为何减1
{pta[1]:=RotateXY(dbTheta,Point(Srcbmp.Width - 1, 0));
pta[2]:=RotateXY(dbTheta,Point(0, Srcbmp.Height - 1));
pta[3]:=RotateXY(dbTheta,Point(Srcbmp.Width - 1, Srcbmp.Height - 1));
}
pta[] := RotateXY(dbTheta,Point(Srcbmp.Width, ));
pta[] := RotateXY(dbTheta,Point(, Srcbmp.Height));
pta[] := RotateXY(dbTheta,Point(Srcbmp.Width, Srcbmp.Height)); DestBmp.PixelFormat := pf32bit;
DestBmp.Canvas.Brush.Color := clWindow; for i := to do
ba[i] := pta[i].x; DestBmp.width := MaxIntValue(ba) - MinIntValue(ba); for i := to do
ba[i] := pta[i].y; DestBmp.Height := MaxIntValue(ba) - MinIntValue(ba); ptc := RotateXY(dbTheta, Point(Srcbmp.Width div , Srcbmp.Height div )); ptTarCenter.x := DestBmp.Width div ;
ptTarCenter.y := DestBmp.Height div ; pta[].x := pta[].x + ptTarCenter.x - ptc.x;
pta[].y := pta[].y + ptTarCenter.y - ptc.y;
pta[].x := pta[].x + ptTarCenter.x - ptc.x;
pta[].y := pta[].y + ptTarCenter.y - ptc.y;
pta[].x := pta[].x + ptTarCenter.x - ptc.x;
pta[].y := pta[].y + ptTarCenter.y - ptc.y; if PlgBlt(DestBmp.Canvas.Handle, pta, Srcbmp.Canvas.Handle,
, , Srcbmp.Width - , Srcbmp.Height - , , , ) then
DestBmp.Canvas.Draw(, , DestBmp)
else
DestBmp.Canvas.TextOut(,,'只支持WinNT内核操作系统.');
end; //毫米单位转换为英寸单位
function MmToInch(Length: Extended): Extended;
begin
Result := Length/25.4;
end;
//英寸单位转换为毫米单位
function InchToMm(Length: Extended): Extended;
begin
Result := Length*25.4;
end;
end.

用中文参数变量,别笑,这样只是为了让大家更好的解读一些重点代码。

注意我这儿的图片质量,都用了高质量,如果觉得处理的大小太大,则可以降低质量来获得小一些的文件

注意:
1、参数值为0时,表示该项不处理。
2、处理为依次执行,即旋转、切边、缩放,后一项的参数,也应参考前一项,而非原图参数
3、缩放只支持等比缩放,也就是只会根据宽或高中的一个值进行缩放,根据哪一个值,则适用于大值等于设置值的处理原则。
4、切边是指对应的边去除设定值,缩放则为处理后的目标值不大于设定值。

delphi JPG图片 旋转 切边 缩放的更多相关文章

  1. 用Js+css3实现图片旋转,缩放,裁剪,滤镜

    还是前端图片的老话题,花了半天时间,东拼西凑,凑出个demo,优点在于代码少,核心代码就6行,目前刚做了旋转,缩放,裁剪,滤镜要js做,网络上也有现成的代码, 但是想做到自定义的滤镜咋办呢?这还要从底 ...

  2. 自定义View实现图片的绘制、旋转、缩放

    1.图片 把一张JPG图片改名为image.jpg,然后拷贝到项目的res-drawable中. 2.activity_main.xml <LinearLayout xmlns:android= ...

  3. Android图片旋转,缩放,位移,倾斜,对称完整示例(一)——imageView.setImageMatrix(matrix)和Matrix

    MainActivity如下: import android.os.Bundle; import android.view.MotionEvent; import android.view.View; ...

  4. WPF图片预览之移动、旋转、缩放

    原文:WPF图片预览之移动.旋转.缩放 RT,这个功能比较常见,但凡涉及到图片预览的都跑不了,在说自己的实现方式前,介绍一个好用的控件:Extended.Toolkit中的Zoombox,感兴趣的同学 ...

  5. Android图片旋转,缩放,位移,倾斜,对称完整演示样例(一)——imageView.setImageMatrix(matrix)和Matrix

    MainActivity例如以下: import android.os.Bundle; import android.view.MotionEvent; import android.view.Vie ...

  6. Vue图片浏览组件v-viewer,支持旋转、缩放、翻转等操作

    v-viewer 用于图片浏览的Vue组件,支持旋转.缩放.翻转等操作,基于viewer.js. 从0.x迁移 你需要做的唯一改动就是手动引入样式文件: 1 import 'viewerjs/dist ...

  7. Fresco 二三事:图片处理之旋转、缩放、裁剪切割图片

    关于Fresco加载图片的处理,例如旋转.裁剪切割图片,在官方文档也都有提到,只是感觉写的不太详细,正好最近项目里有类似需求,所以分享一些使用小tip,后面的朋友就不用再走弯路浪费时间了.(测试图片分 ...

  8. 【CSS3动画】transform对文字及图片的旋转、缩放、倾斜和移动

    前言:之前我有写过CSS3的transform这一这特性,对于它的用法,还不是很透彻,今天补充补充,呵呵 你懂的,小司机准备开车了. a)再提一提transform的四个属性 ①旋转--->ro ...

  9. Qt5:Qt中图片的翻转,旋转,缩放,扭曲操作

    具体用到了  mirror()  shear()  scaled() translate() rotate() 等函数函数等会儿再写 (其中  translate() 和 rotate() 俩函数组合 ...

随机推荐

  1. mongodb Decimal Spring data mongodb Decimal128 SpringMvc 序列化字符串 json converter

    Mongodb 3.4 就开始支持Decimal 类型,解决double的精度问题,但是不太好用,MapReduce的时候Array.sum 也不能计算 Decimal.比较坑,但是聚合可以用 Spr ...

  2. Luogu P2888 [USACO07NOV]牛栏Cow Hurdles

    题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gan ...

  3. java调用shell脚本,并获得结果集的例子

    /** * 运行shell脚本 * @param shell 需要运行的shell脚本 */ public static void execShell(String shell){ try { Run ...

  4. linux iptables配置

    防火墙硬件防火墙软件防火墙: 应用层防火墙 网络层防火墙:linux包过滤防火墙linux包过滤防火墙netfilter:位于linux内核中的包过滤功能体系,称为linux防火墙的"内核态 ...

  5. 用开源的 ffmpeg 实现屏幕录像机

    在我看来,FFmpeg 绝对是一个很酷的应用.那么,它究竟有什么用呢?简单地讲,FFmpeg 相当于一个屏幕录像机.你可以使用它将屏幕上的操作过程录制下来,然后再将其播放给别人看.我们可以利用它制作教 ...

  6. Linux 系统裁剪笔记 3

    说到裁减Linux,无非是为了减小磁盘占用或者是为了某些特定场合的应用(如嵌入式系统).以RedHat 7.3为例,其最小安装仍然达到了300M,这不得不让人对一直号称小而全的Linux系统感到疑惑. ...

  7. JSP自定义标签配置

    JSP自定义标签配置 JSP自定义标签 <taglib>         <taglib-uri>/WEB-INF/you.tld</taglib-uri>     ...

  8. ASP.NET Core 2.0 : 六. 举个例子来聊聊它的依赖注入

    本文通过一个维修工与工具库的例子形象的描述一下为什么要用依赖注入.它的工作原理是什么样的, 然后根据这个类比一下ASP.NET Core 中的依赖注入, 从而深刻了解它的使用方法.注意事项以及回收机制 ...

  9. Java并发系列[8]----CyclicBarrier源码分析

    现实生活中我们经常会遇到这样的情景,在进行某个活动前需要等待人全部都齐了才开始.例如吃饭时要等全家人都上座了才动筷子,旅游时要等全部人都到齐了才出发,比赛时要等运动员都上场后才开始.在JUC包中为我们 ...

  10. JS对select动态添加options操作(主流浏览器兼容)

    之前项目中,遇到一个表单提交的页面,里面有多级下拉框联动的复杂逻辑,因此当时在做的过程中也是学到了不少容易出现问题的地方,下面就整理下当时遇到的一些关于下拉框的操作,并指出其中的一些注意点和坑: 有如 ...