这是一段可以旋转任意角度的代码:
///////////////////////////////// /
////// designed by billy_phd /////
//////////////////////////////////
unit urotate;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Spin;
type
Trgbarray = array[0..32767]of trgbtriple;
prgbarray=^Trgbarray;
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
OpenDialog1: TOpenDialog;
SpinEdit1: TSpinEdit;
SpinEdit2: TSpinEdit;
Image2: TImage;
procedure Button1Click(Sender: TObject);
procedure rotatebitmap;
procedure SpinEdit1Change(Sender: TObject);
procedure SpinEdit2Change(Sender: TObject);
private
{ Private declarations }
rotatedbitmap:tbitmap;
sourcebitmap:tbitmap;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tform1.rotatebitmap;
var rowrotated,roworiginal
rgbarray;
i,j,ioriginal,joriginal,jprime,iprime:integer;
sinthed,costhed:double;
thed:double;
begin
rotatedbitmap:=tbitmap.Create;
rotatedbitmap.Width:=sourcebitmap.Width;
rotatedbitmap.Height:=sourcebitmap.Height;
rotatedbitmap.PixelFormat:=pf24bit;
thed:=-(spinedit1.Value+spinedit2.Value/100)*pi/180;
sinthed:=sin(thed);
costhed:=cos(thed);
//through my test if i use :for j:=rotatedbitmap.height-1 downto 0 do ;has the
//same result;
for j:=0 to rotatedbitmap.Height-1 do
begin
rowrotated:=rotatedbitmap.ScanLine[j];
jprime:=2*j+1;
for i:=0 to rotatedbitmap.Width-1 do
begin
iprime:=2*i+1;
//if ioriginal:=-(round(iprime*costhed-jprime*sinthed)-1) div 2 ;
//joriginal:=(round(jprime*costhed+iprime*sinthed)-1) div 2 ;we
//can get another graphics,so we can change the diaplay of rotation
//by choosing the proper mathematical function
ioriginal:=(round(iprime*costhed-jprime*sinthed)-1) div 2;
joriginal:=(round(jprime*costhed+iprime*sinthed)-1) div 2 ;
if (ioriginal>=0) and (ioriginal<=rotatedbitmap.Width-1) and(joriginal>=0) and(joriginal<=rotatedbitmap.Height-1)
then begin
roworiginal:=sourcebitmap.ScanLine[joriginal];
rowrotated
:=roworiginal[ioriginal];
end
else
begin
rowrotated.rgbtBlue:=255;
rowrotated.rgbtGreen:=0;
rowrotated.rgbtRed:=0;
end;
end;
end;
image1.Picture.Graphic:=rotatedbitmap;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sourcebitmap:=tbitmap.Create;
if opendialog1.Execute then
sourcebitmap.LoadFromFile(opendialog1.FileName);
image2.Picture.Graphic:=sourcebitmap;
rotatebitmap;
end;
procedure TForm1.SpinEdit1Change(Sender: TObject);
begin
rotatebitmap;
end;
procedure TForm1.SpinEdit2Change(Sender: TObject);
begin
rotatebitmap;
end;
end.
别忘了加分哦