首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

delphi中,怎么将位图90°旋转

2012-03-01 
delphi中,如何将位图90旋转?如何将位图16X16的单色在delphi中旋转为[解决办法]Delphi(Pascal) code//基于G

delphi中,如何将位图90°旋转?
如何将位图16X16的单色 


在delphi中旋转为



[解决办法]

Delphi(Pascal) code
//基于GDI的方法procedure Rotate90(Bitmap: TBitmap);// 顺时针var  aStream: TMemorystream;  header: TBITMAPINFO;  dc: hDC;  P: ^THelpRGB;  x, y, b, h: Integer;  RowOut: pRGBArray;begin  aStream := TMemoryStream.Create;  //设置大小,必须是4的倍数  aStream.SetSize(Bitmap.Height * Bitmap.Width * 4);  with header.bmiHeader do   begin    biSize := SizeOf(TBITMAPINFOHEADER);     biWidth := Bitmap.Width;      biHeight := Bitmap.Height;      biPlanes := 1;    biBitCount := 32;     biCompression := 0;    biSizeimage := aStream.Size;    biXPelsPerMeter := 1;      biYPelsPerMeter := 1;      biClrUsed := 0;    biClrImportant := 0;  end;  dc := GetDC(0);  P := aStream.Memory;  GetDIBits(dc, Bitmap.Handle, 0, Bitmap.Height, P, header, dib_RGB_Colors);  ReleaseDC(0, dc);  b := bitmap.Height;   h := bitmap.Width;   bitmap.Width := b;  bitmap.height := h;  for y := 0 to (h - 1) do  begin    rowOut := Bitmap.ScanLine[y];    P := aStream.Memory;     inc(p, y);     for x := 0 to (b - 1) do    begin      rowout[x] := p^.rgb;      inc(p, h);    end;  end;  aStream.Free; end;//调用注意,会改变原来的图像Rotate90(Image.picture.bitmap);基于GDI+的方法:procedure RotalBmp(FAngle: Integer); var Bmp : TGpBitmap;     gp : TGpGraphics;     M : TGpMatrix;begin  Bmp := TGpBitmap.Create('a.JPG');  try    Gr := GpRect(0,0,Bmp.Width,Bmp.Height);    gp := TGpGraphics.Create(pb1.Canvas.Handle);    M := TGpMatrix.Create;    Center.X := pb1.Width div 2;    Center.Y := pb1.Height div 2;    M.RotateAt(FAngle,Center);//FAngle为角度    gp.SetTransform(M);    gp.DrawImage(Bmp,Gr);  finally    gp.Free;    Bmp.Free;    m.Free;  end;end; 

热点排行