以前的笔记,偶也忘了从哪里抄来的了,呵呵
// ****************************************************************************
// 顺时针旋转90度
// 参数:
// bmp 输入Bitmap
// bmpOut 输出Bitmap
// 返回值:
// 成功 True
// 失败 False
// ****************************************************************************
function Rotate90(bmp:TBitmap;var bmpOut:TBitmap):boolean;
var
aStream: TMemorystream; //内存流
header: TBITMAPINFO;
dc: hDC;
P: ^THelpRGB;
x, y, b, h: Integer;
RowOut: pRGBArray;
begin
try
//创建内存流
aStream := TMemoryStream.Create;
//设置大小,必须是4的倍数
aStream.SetSize(bmp.Height * bmp.Width * 4);
with header.bmiHeader do //操作位图文件
begin
biSize := SizeOf(TBITMAPINFOHEADER); //大小
biWidth := bmp.Width; //位图宽
biHeight := bmp.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, bmp.Handle, 0, bmp.Height, P, header, dib_RGB_Colors);
ReleaseDC(0, dc);
b := bmp.Height; //源图高
h := bmp.Width; //源图宽
//指定要创建的位图的大小尺寸
bmp.Width := b;
bmp.height := h;
for y := 0 to (h - 1) do
begin
rowOut := bmp.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; //释放资源
bmpOut.Width := bmp.Width;
bmpOut.Height := bmp.Height;
bmpOut.Assign(bmp);
result := true;
except
Result := false;
end;
end;