如何实现图片的旋转???急!!! 我现在要把一张图片进行任意角度的旋转,具体应该怎么做呢?各位给个思路,有代码或是给个例子就最好了,先谢谢各位!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://community.csdn.net/Expert/topic/3229/3229758.xml?temp=.6042292 unit unitImage;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, math;type TForm1 = class(TForm) Image1: TImage; Image2: TImage; Image3: TImage; Button2: TButton; Button3: TButton; Button4: TButton; Image4: TImage; Button1: TButton; procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } procedure bmp_rotate(src, dst: tbitmap; angle: extended); public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}{ TForm1 }procedure TForm1.bmp_rotate(src, dst: tbitmap; angle: extended);var c1x, c1y, c2x, c2y: integer; p1x, p1y, p2x, p2y: integer; radius, n: integer; alpha: extended; c0, c1, c2, c3: tcolor;begin //½«½Ç¶Èת»»ÎªPIÖµ angle := (angle / 180) * pi; // ¼ÆËãÖÐÐĵ㣬Äã¿ÉÒÔÐÞ¸ÄËü c1x := src.width div 2; c1y := src.height div 2; c2x := dst.width div 2; c2y := dst.height div 2; // ²½ÖèÊýÖµnumber if c2x < c2y then n := c2y else n := c2x; dec(n, 1); // ¿ªÊ¼Ðýת for p2x := 0 to n do begin for p2y := 0 to n do begin if p2x = 0 then alpha := pi / 2 else alpha := arctan2(p2y, p2x); radius := round(sqrt((p2x * p2x) + (p2y * p2y))); p1x := round(radius * cos(angle + alpha)); p1y := round(radius * sin(angle + alpha)); c0 := src.canvas.pixels[c1x + p1x, c1y + p1y]; c1 := src.canvas.pixels[c1x - p1x, c1y - p1y]; c2 := src.canvas.pixels[c1x + p1y, c1y - p1x]; c3 := src.canvas.pixels[c1x - p1y, c1y + p1x]; dst.canvas.pixels[c2x + p2x, c2y + p2y] := c0; dst.canvas.pixels[c2x - p2x, c2y - p2y] := c1; dst.canvas.pixels[c2x + p2y, c2y - p2x] := c2; dst.canvas.pixels[c2x - p2y, c2y + p2x] := c3; end; application.processmessages end;end;procedure TForm1.Button2Click(Sender: TObject);var i, j: integer;begin //90 image2.Picture.Bitmap.Height := image1.picture.width; image2.Picture.Bitmap.Width := image1.picture.height; for i := 0 to image1.Height do for j := 0 to image1.Width do image2.canvas.Pixels[(-i + image1.Height), j] := image1.canvas.Pixels[j, i];end;procedure TForm1.Button3Click(Sender: TObject);var i, j: integer;begin //180 image3.Picture.Bitmap.Height := image1.picture.Height; image3.Picture.Bitmap.Width := image1.picture.Width; for i := 0 to image1.Height do for j := 0 to image1.Width do image3.canvas.Pixels[(image1.Width - j), (image1.Height - i)] := image1.canvas.Pixels[j, i];end;procedure TForm1.Button4Click(Sender: TObject);var i, j: integer;begin //270 image4.Picture.Bitmap.Height := image1.picture.Width; image4.Picture.Bitmap.Width := image1.picture.Height; for i := 0 to image1.Height do for j := 0 to image1.Width do image4.canvas.Pixels[i, (image1.Width-j)] := image1.canvas.Pixels[j, i];end;end. 记住平面旋转矩阵 cosA -sinA sinA cosA就行了 X=xcosA-ysinA Y=xsinA+ycosA 这里都有:http://www.delphibbs.com/delphibbs/dispq.asp?lid=757447http://www.delphibbs.com/delphibbs/dispq.asp?lid=1600015自己搜一下就可以找到一大把。 记住平面旋转矩阵 cosA -sinA sinA cosA就行了 X=xcosA-ysinA Y=xsinA+ycosA 直接用控件吧,就很简单了http://www.evget.com/view/viewProductInfo.asp?productId=120 delphi 配置文件怎么写 好奇怪的问题 大家帮帮忙 请问谁有《跨进程获取其他程序的DBGrid内容》的源码? 请问Delphi怎么和Web通讯 ClientDataSet的问题 有哪位仁兄知道怎么读写.db文件 如何实现窗口的自动隐藏???? ★如何在文本文件里添加字符串?★ 救命啊,我受不了了!关于多次查询!第二帖!200分了!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 绝对难题: dbgrid绑定刷新问题 如何在没有DELPHI机器里运行带数据表的程序?
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, math;type
TForm1 = class(TForm)
Image1: TImage;
Image2: TImage;
Image3: TImage;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Image4: TImage;
Button1: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
procedure bmp_rotate(src, dst: tbitmap; angle: extended);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}{ TForm1 }procedure TForm1.bmp_rotate(src, dst: tbitmap; angle: extended);
var
c1x, c1y, c2x, c2y: integer;
p1x, p1y, p2x, p2y: integer;
radius, n: integer;
alpha: extended;
c0, c1, c2, c3: tcolor;
begin
//½«½Ç¶Èת»»ÎªPIÖµ
angle := (angle / 180) * pi;
// ¼ÆËãÖÐÐĵ㣬Äã¿ÉÒÔÐÞ¸ÄËü
c1x := src.width div 2;
c1y := src.height div 2;
c2x := dst.width div 2;
c2y := dst.height div 2; // ²½ÖèÊýÖµnumber
if c2x < c2y then
n := c2y
else
n := c2x;
dec(n, 1); // ¿ªÊ¼Ðýת
for p2x := 0 to n do begin
for p2y := 0 to n do begin
if p2x = 0 then
alpha := pi / 2
else
alpha := arctan2(p2y, p2x);
radius := round(sqrt((p2x * p2x) + (p2y * p2y)));
p1x := round(radius * cos(angle + alpha));
p1y := round(radius * sin(angle + alpha)); c0 := src.canvas.pixels[c1x + p1x, c1y + p1y];
c1 := src.canvas.pixels[c1x - p1x, c1y - p1y];
c2 := src.canvas.pixels[c1x + p1y, c1y - p1x];
c3 := src.canvas.pixels[c1x - p1y, c1y + p1x]; dst.canvas.pixels[c2x + p2x, c2y + p2y] := c0;
dst.canvas.pixels[c2x - p2x, c2y - p2y] := c1;
dst.canvas.pixels[c2x + p2y, c2y - p2x] := c2;
dst.canvas.pixels[c2x - p2y, c2y + p2x] := c3;
end;
application.processmessages
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i, j: integer;
begin
//90
image2.Picture.Bitmap.Height := image1.picture.width;
image2.Picture.Bitmap.Width := image1.picture.height;
for i := 0 to image1.Height do
for j := 0 to image1.Width do
image2.canvas.Pixels[(-i + image1.Height),
j] := image1.canvas.Pixels[j, i];
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i, j: integer;
begin
//180
image3.Picture.Bitmap.Height := image1.picture.Height;
image3.Picture.Bitmap.Width := image1.picture.Width;
for i := 0 to image1.Height do
for j := 0 to image1.Width do
image3.canvas.Pixels[(image1.Width
- j), (image1.Height - i)] := image1.canvas.Pixels[j, i];
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i, j: integer;
begin
//270
image4.Picture.Bitmap.Height := image1.picture.Width;
image4.Picture.Bitmap.Width := image1.picture.Height;
for i := 0 to image1.Height do
for j := 0 to image1.Width do
image4.canvas.Pixels[i, (image1.Width-j)] := image1.canvas.Pixels[j, i];
end;end.
cosA -sinA
sinA cosA就行了
X=xcosA-ysinA
Y=xsinA+ycosA
http://www.delphibbs.com/delphibbs/dispq.asp?lid=757447http://www.delphibbs.com/delphibbs/dispq.asp?lid=1600015自己搜一下就可以找到一大把。
cosA -sinA
sinA cosA就行了
X=xcosA-ysinA
Y=xsinA+ycosA