unit zhenzheng;
希望实现的效果是:能绕一个竖直轴旋转
问题应该在转换的坐标上
希望高手帮忙
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Menus, ComCtrls,math;
type
  TForm1 = class(TForm)
    Image1: TImage;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  //focus,distance:integer;
  theta:double;
  pixels:array of byte; //动态数组  存放RGB分量
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
y1,x1,thetaX,theta1:double;
x,y,j,i,w,h:integer;
temp:array of byte; //动态数组  存放RGB分量
newbmp:Tbitmap;
a,b,pos:integer;
red,green,blue:double;
begin
w:=image1.Picture.Width;
h:=image1.Picture.Height;
newbmp:= TBitmap.Create;
newbmp.Width:=w;
newbmp.Height:=h;
image1.picture.bitmap.pixelformat:=pf24bit;
theta1:= 90; //度数
setlength(pixels,w*h*3);
for i:=0 to h-1 do
move(image1.picture.bitmap.scanline[i]^,pixels[i*w*3],w*3);
//参数
thetaX:=theta1*3.1416/180;setlength(temp,w*h*3);
//透视变换
for y:=0 to h-1 do
begin
 for x:=0 to w-1 do
  begin
  //变换过程
   x1:=w-1-x;
   y1:=h-1-y;
  a:=trunc(x1);
  b:=trunc(y1);
  if ((a>=0)and(a<w-1)and(b>=0)and(b<h-1))then
  begin
  pos:=b*w*3+a*3;
  //求出R,G,B颜色分量
  //蓝色
  blue:=(pixels[pos]*(a+1-x1)+pixels[pos+3]*(x1-a))*(b+1-y1)+(pixels[pos+w*3]*(a+1-x1)+pixels[pos+w*3+3]*(x1-a))*(y1-b);
   pos:=pos+1;
   //绿色
  green:=(pixels[pos]*(a+1-x1)+pixels[pos+3]*(x1-a))*(b+1-y1)+(pixels[pos+w*3]*(a+1-x1)+pixels[pos+w*3+3]*(x1-a))*(y1-b);
   pos:=pos+1;
   //红色
  red:=(pixels[pos]*(a+1-x1)+pixels[pos+3]*(x1-a))*(b+1-y1)+(pixels[pos+w*3]*(a+1-x1)+pixels[pos+w*3+3]*(x1-a))*(y1-b);
   temp[y*w*3+x*3]:=trunc(Blue);
   temp[y*w*3+x*3+1]:=trunc(Green);
   temp[y*w*3+x*3+2]:=trunc(Red);
   end
   else   begin
  temp[y*w*3+x*3+2]:=255;
  temp[y*w*3+x*3+1]:=255;
  temp[y*w*3+x*3]:=255;
   end;
end;
end;
//拷贝到pixels数组
for x:=0 to w*h*3-1 do
  pixels[x]:=temp[x];
// 根据像素矩阵重绘图
w:=trunc(w*cos(thetaX));
image1.Picture.Bitmap.Width:=w;
image1.Picture.Bitmap.Height:=h;
for i:=0 to h-1 do
  move(pixels[i*w*3],image1.picture.bitmap.scanline[i]^,w*3);
image1.Repaint;
newbmp.Free;
end;end.