请问:如何才能实现jpg图片的旋转并保存!谢谢! 请问:如何才能实现jpg图片的旋转并保存!谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 请教一下,我已经下载了gdiplus.rar,但应该怎么用?好像是要把它编译成dcu,但不知道怎么做! procedure TForm1.Rotate(Srcbmp, DestBmp: TBitmap; dbTheta: Double);var ptOrgCenter, ptTarCenter, ptc: TPoint; pta: array[0..3] of TPoint; ba: array[0..3] 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 / 180; _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 2; ptOrgCenter.y := Srcbmp.Height div 2; pta[0] := RotateXY(dbTheta,Point(0, 0)); //这里不知道原来为何减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[1] := RotateXY(dbTheta,Point(Srcbmp.Width, 0)); pta[2] := RotateXY(dbTheta,Point(0, Srcbmp.Height)); pta[3] := RotateXY(dbTheta,Point(Srcbmp.Width, Srcbmp.Height)); DestBmp.PixelFormat := pf32bit; DestBmp.Canvas.Brush.Color := clWindow; for i := 0 to 3 do ba[i] := pta[i].x; DestBmp.width := MaxIntValue(ba) - MinIntValue(ba); for i := 0 to 3 do ba[i] := pta[i].y; DestBmp.Height := MaxIntValue(ba) - MinIntValue(ba); ptc := RotateXY(dbTheta, Point(Srcbmp.Width div 2, Srcbmp.Height div 2)); ptTarCenter.x := DestBmp.Width div 2; ptTarCenter.y := DestBmp.Height div 2; pta[0].x := pta[0].x + ptTarCenter.x - ptc.x; pta[0].y := pta[0].y + ptTarCenter.y - ptc.y; pta[1].x := pta[1].x + ptTarCenter.x - ptc.x; pta[1].y := pta[1].y + ptTarCenter.y - ptc.y; pta[2].x := pta[2].x + ptTarCenter.x - ptc.x; pta[2].y := pta[2].y + ptTarCenter.y - ptc.y; if PlgBlt(DestBmp.Canvas.Handle, pta, Srcbmp.Canvas.Handle, 0, 0, Srcbmp.Width - 1, Srcbmp.Height - 1, 0, 0, 0) then DestBmp.Canvas.Draw(0, 0, DestBmp) else DestBmp.Canvas.TextOut(0,0,'PlgBlt currently supported only on WinNT.'); end;使用时Rotate(Img, RImg, 270); //由于函数是左向旋转,所以这里角度设置为270。 只要在菜单“Tools”->“Environment Options”中选“Library”标签,然后点击旁边的“...”按钮,选择你的gdiplus下pas目录即可。然后在你的程序中的uses中,把“GDIPAPI”、“GDIPOBJ”加进去就可以使用了。例子程序如下:var ggGraphics: TGpGraphics; intAngle: integer; giImg: TGpImage;begin intAngle := 30; //旋转角度 giImg := TGpImage.Create('C:\Test.jpg'); //要画的图片文件(可以是JPG、bmp、png、gif等GDI+所能认到的所有图片格式) ggGraphics:= TGPGraphics.Create(DrawImage.Canvas.Handle); //DrawImage为你要画图像的Image对象,只要是有Canvas的对象都可以。 ggGraphics.SetSmoothingMode(QualityModeHigh); //图像平滑质量 ggGraphics.RotateTransform(intAngle, MatrixOrderAppend); //旋转画布 ggGraphics.DrawImage(ClockHandImg, 0, 0); //画图片 ggGraphics.Free; giImg.Free;end;以上程序就可以把图片旋转任意角度不过此程序有一缺点,就是旋转中心为画布的坐标左上角,在大多数情况下,这显然不是我们所需要的,我们一般需要图片能以某点为中心旋转,因此我们可以使用矩阵“Matrix”来进行图片的旋转。但对于初学者来讲,这个方法过于繁琐。那么是否有一简单易行的方法呢?本人现有另一个方法,即简单又快速,原理如下:TGpGraphics另外有三个方法:“TranslateTransform”:这个方法是用来放大画布的坐标。“BeginContainer”:这个方法很实用,即,当TGpGraphics执行该方法后,画布的旋转只影响以后画的对象。“EndContainer”:这个方法与上一方法相对应,当TGpGraphics执行该方法后就结束上一方法的特性。我们可以根据以上三个方法来实现图片以某点为中心旋转。首先把画布的坐标原点放大到需要的地方,以图片的中心点坐标为宜。然后执行第二个方法并放置画布,接着把要画的图片以原点为中心点画上去即可,最后执行上面第三个方法来结束这个动作。这样图片就能以中心点为旋转点进行旋转了。此法有个好处就是用不着三角函数来计算图片旋转后四个点的位置。在画图片时,只当还没有旋转,因为此时是画布进行了旋转。根据以上方法,只要在上面代码的基础上稍作修改即可,代码如下:var ggGraphics: TGpGraphics; intAngle: integer; giImg: TGpImage; gcContainer: GraphicsContainer;begin intAngle := 30; //旋转角度 giImg := TGpImage.Create('C:\Test.jpg'); //要画的图片文件(可以是JPG、bmp、png、gif等GDI+所能认到的所有图片格式) ggGraphics:= TGPGraphics.Create(DrawImage.Canvas.Handle); //DrawImage为你要画图像的Image对象,只要是有Canvas的对象都可以。 ggGraphics.SetSmoothingMode(QualityModeHigh); //图像平滑质量 ggSmooth.TranslateTransform(200, 200); //把坐标放大至需要的地方 gcContainer := ggSmooth.BeginContainer; //作用见上 ggGraphics.RotateTransform(intAngle, MatrixOrderAppend); //旋转画布 ggGraphics.DrawImage(ClockHandImg, -giImg.GetWidth div 2, -giImg.GetHeight div 2); //画图片,图片的中心与画布的原点重合 ggSmooth.EndContainer(gcContainer); ggGraphics.Free; giImg.Free;end;以上程序在Delphi7中实现。 javascript怎样实现,图片旋转并保存 问有比较多兼职经验的高手几个问题 关于U盘启动WINPE的问题 怎么向动态申请长度的Char数组里写入字符 网络上两台电脑互拷文件 十万火急!!!!!!!!!!!! ReprotBuilder报表出错 这样的SQL语句怎么写 帮我看看这对不对呀,老是记录数目为0???? 急!!!DBGRID的问题 高手 请进。 它是我这些年来碰到的最大DELPHI难题,,,,,,NEED HELP. 动态生成DBchart显示不一致 关于ASCII码的原理! 內存訪問問題,煩透了
好像是要把它编译成dcu,但不知道怎么做!
procedure TForm1.Rotate(Srcbmp, DestBmp: TBitmap; dbTheta: Double);
var
ptOrgCenter, ptTarCenter, ptc: TPoint;
pta: array[0..3] of TPoint;
ba: array[0..3] 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 / 180;
_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 2;
ptOrgCenter.y := Srcbmp.Height div 2; pta[0] := RotateXY(dbTheta,Point(0, 0));
//这里不知道原来为何减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[1] := RotateXY(dbTheta,Point(Srcbmp.Width, 0));
pta[2] := RotateXY(dbTheta,Point(0, Srcbmp.Height));
pta[3] := RotateXY(dbTheta,Point(Srcbmp.Width, Srcbmp.Height));
DestBmp.PixelFormat := pf32bit;
DestBmp.Canvas.Brush.Color := clWindow; for i := 0 to 3 do
ba[i] := pta[i].x; DestBmp.width := MaxIntValue(ba) - MinIntValue(ba); for i := 0 to 3 do
ba[i] := pta[i].y; DestBmp.Height := MaxIntValue(ba) - MinIntValue(ba); ptc := RotateXY(dbTheta, Point(Srcbmp.Width div 2, Srcbmp.Height div 2)); ptTarCenter.x := DestBmp.Width div 2;
ptTarCenter.y := DestBmp.Height div 2; pta[0].x := pta[0].x + ptTarCenter.x - ptc.x;
pta[0].y := pta[0].y + ptTarCenter.y - ptc.y;
pta[1].x := pta[1].x + ptTarCenter.x - ptc.x;
pta[1].y := pta[1].y + ptTarCenter.y - ptc.y;
pta[2].x := pta[2].x + ptTarCenter.x - ptc.x;
pta[2].y := pta[2].y + ptTarCenter.y - ptc.y; if PlgBlt(DestBmp.Canvas.Handle, pta, Srcbmp.Canvas.Handle,
0, 0, Srcbmp.Width - 1, Srcbmp.Height - 1, 0, 0, 0) then
DestBmp.Canvas.Draw(0, 0, DestBmp)
else
DestBmp.Canvas.TextOut(0,0,'PlgBlt currently supported only on WinNT.');
end;使用时
Rotate(Img, RImg, 270); //由于函数是左向旋转,所以这里角度设置为270。
只要在菜单“Tools”->“Environment Options”中选“Library”标签,然后点击旁边的“...”按钮,选择你的gdiplus下pas目录即可。然后在你的程序中的uses中,把“GDIPAPI”、“GDIPOBJ”加进去就可以使用了。例子程序如下:var
ggGraphics: TGpGraphics;
intAngle: integer;
giImg: TGpImage;
begin
intAngle := 30; //旋转角度 giImg := TGpImage.Create('C:\Test.jpg'); //要画的图片文件(可以是JPG、bmp、png、gif等GDI+所能认到的所有图片格式)
ggGraphics:= TGPGraphics.Create(DrawImage.Canvas.Handle); //DrawImage为你要画图像的Image对象,只要是有Canvas的对象都可以。
ggGraphics.SetSmoothingMode(QualityModeHigh); //图像平滑质量
ggGraphics.RotateTransform(intAngle, MatrixOrderAppend); //旋转画布
ggGraphics.DrawImage(ClockHandImg, 0, 0); //画图片
ggGraphics.Free;
giImg.Free;
end;以上程序就可以把图片旋转任意角度
不过此程序有一缺点,就是旋转中心为画布的坐标左上角,在大多数情况下,这显然不是我们所需要的,我们一般需要图片能以某点为中心旋转,因此我们可以使用矩阵“Matrix”来进行图片的旋转。
但对于初学者来讲,这个方法过于繁琐。那么是否有一简单易行的方法呢?本人现有另一个方法,即简单又快速,原理如下:
TGpGraphics另外有三个方法:
“TranslateTransform”:这个方法是用来放大画布的坐标。
“BeginContainer”:这个方法很实用,即,当TGpGraphics执行该方法后,画布的旋转只影响以后画的对象。
“EndContainer”:这个方法与上一方法相对应,当TGpGraphics执行该方法后就结束上一方法的特性。
我们可以根据以上三个方法来实现图片以某点为中心旋转。首先把画布的坐标原点放大到需要的地方,以图片的中心点坐标为宜。然后执行第二个方法并放置画布,接着把要画的图片以原点为中心点画上去即可,最后执行上面第三个方法来结束这个动作。这样图片就能以中心点为旋转点进行旋转了。此法有个好处就是用不着三角函数来计算图片旋转后四个点的位置。在画图片时,只当还没有旋转,因为此时是画布进行了旋转。
根据以上方法,只要在上面代码的基础上稍作修改即可,代码如下:var
ggGraphics: TGpGraphics;
intAngle: integer;
giImg: TGpImage;
gcContainer: GraphicsContainer;
begin
intAngle := 30; //旋转角度 giImg := TGpImage.Create('C:\Test.jpg'); //要画的图片文件(可以是JPG、bmp、png、gif等GDI+所能认到的所有图片格式)
ggGraphics:= TGPGraphics.Create(DrawImage.Canvas.Handle); //DrawImage为你要画图像的Image对象,只要是有Canvas的对象都可以。
ggGraphics.SetSmoothingMode(QualityModeHigh); //图像平滑质量
ggSmooth.TranslateTransform(200, 200); //把坐标放大至需要的地方
gcContainer := ggSmooth.BeginContainer; //作用见上
ggGraphics.RotateTransform(intAngle, MatrixOrderAppend); //旋转画布
ggGraphics.DrawImage(ClockHandImg, -giImg.GetWidth div 2, -giImg.GetHeight div 2); //画图片,图片的中心与画布的原点重合
ggSmooth.EndContainer(gcContainer);
ggGraphics.Free;
giImg.Free;
end;
以上程序在Delphi7中实现。