楼主你的bmp_rotate 中不是有旋转吗? 试下面的代码试procedure rotate(sur:pchar;bmp:Tbitmap;cx,cy:integer;angle:integer); var x1,y1,x3,y3 :integer //x1,y1 为平移坐标 x3,y3为旋转的新坐标 x,y,h,w,widthbytes,dst,v:integer; hcos,hsin:double; tmp:PFcolor; hu:double; begin hu:=angle*3.1415/180; hcos:=cos(hu); hsin:=sin(hu); h:=bmp.Height; w:=bmp.Width ; widthbytes:=integer(bmp.scanline[0])-integer(bmp.scanline[1]); dst:=integer(bmp.ScanLine[h-1]); fillchar(pchar(dst)^,widthbytes*h,0); //使图像全黑 for y:=0 to h-1 do begin y1:=y -(h-cy); //平移下的y for x:=0 to W-1 do begin x1:=x-cx; //平移下的x x3:=round(x1*hcos-y1*hsin); y3:=round(x1*hsin+y1*hcos); //平移下的新坐标 x3:=x3+cx; y3:=y3+(h-cy); //转换回原坐标 if (x3>=0) and (x3<w-1) and (y3>=0) and (y3<h-1) then pfcolor(dst+x*3+y*widthbytes)^:= pfcolor(integer(sur)+x3*3+y3*widthbytes)^; end; end; end; angle为旋转的角度,cx、cy为旋转中心, cx=width div 2,cy=height div 2即以图像的中心为旋转中心。此程序处理速度快,可处理大图片。
procedure TForm2.Button3Click(Sender: TObject);
var
bmp1, bmp2 : TBitmap;
dpix_p, dpiy_p, dpix_s, dpiy_s, width, height : Integer;
begin
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create; Printer.BeginDoc;
dpix_p := GetDeviceCaps(Printer.Handle,LOGPIXELSX);
dpiy_p := GetDeviceCaps(Printer.Handle,LOGPIXELSY); dpix_s := GetDeviceCaps(GetDC(0),LOGPIXELSX);
dpiy_s := GetDeviceCaps(GetDC(0),LOGPIXELSY); width := trunc(Printer.PageWidth / dpix_p * dpix_s);
height := trunc(Printer.PageHeight / dpiy_p * dpiy_s); bmp1.Width := width;
bmp1.Height := height; Printer.Canvas.Draw(100, 100, Image1.Picture.Bitmap); StretchBlt(bmp1.Canvas.Handle, 0, 0,
bmp1.Width, bmp1.Height,
Printer.Canvas.Handle, 0, 0,
width, height, SRCCOPY); bmp2.Width := height;
bmp2.Height := width;
bmp_rotate(bmp1, bmp2, 270);
Image2.Picture.Bitmap.Width := width;
Image2.Picture.Bitmap.Height := height; //这里我没有把bmp2拷贝回画布,而是在Image2中看效果,但是,得到的是空白,没有图片。
StretchBlt(Image2.Picture.Bitmap.Canvas.Handle, 0, 0,
Image2.Width, Image2.Height,
bmp2.Canvas.Handle, 0, 0,
width, height, SRCCOPY);
Image2.Refresh;
// Printer.EndDoc; bmp1.Free;
bmp2.Free;
end;
var
x1,y1,x3,y3 :integer //x1,y1 为平移坐标 x3,y3为旋转的新坐标
x,y,h,w,widthbytes,dst,v:integer;
hcos,hsin:double;
tmp:PFcolor;
hu:double;
begin
hu:=angle*3.1415/180;
hcos:=cos(hu); hsin:=sin(hu);
h:=bmp.Height; w:=bmp.Width ;
widthbytes:=integer(bmp.scanline[0])-integer(bmp.scanline[1]);
dst:=integer(bmp.ScanLine[h-1]);
fillchar(pchar(dst)^,widthbytes*h,0); //使图像全黑
for y:=0 to h-1 do
begin
y1:=y -(h-cy); //平移下的y
for x:=0 to W-1 do
begin
x1:=x-cx; //平移下的x
x3:=round(x1*hcos-y1*hsin);
y3:=round(x1*hsin+y1*hcos); //平移下的新坐标
x3:=x3+cx;
y3:=y3+(h-cy); //转换回原坐标
if (x3>=0) and (x3<w-1) and (y3>=0) and (y3<h-1) then
pfcolor(dst+x*3+y*widthbytes)^:=
pfcolor(integer(sur)+x3*3+y3*widthbytes)^;
end;
end;
end;
angle为旋转的角度,cx、cy为旋转中心, cx=width div 2,cy=height div 2即以图像的中心为旋转中心。此程序处理速度快,可处理大图片。
不过按我说的思路,现在的问题不是位图的旋转,而是将打印机画布转换为位图时,在Image控件中显示的空白,不知道是什么原因,谢谢!