delphi timage 旋转90度
时间: 2023-07-28 14:07:38 浏览: 58
你可以使用TImage的Canvas属性来实现旋转操作,具体代码如下:
```
procedure TForm1.Button1Click(Sender: TObject);
var
bmp: TBitmap;
begin
bmp := TBitmap.Create;
try
// 将 TImage 中的图像复制到 bmp 中
bmp.Width := Image1.Picture.Width;
bmp.Height := Image1.Picture.Height;
bmp.Canvas.Draw(0, 0, Image1.Picture.Graphic);
// 旋转 bmp
bmp.Canvas.StretchDraw(Rect(0, 0, bmp.Height, bmp.Width),
bmp, Rect(0, 0, bmp.Width, bmp.Height));
// 将旋转后的图像显示在 TImage 中
Image1.Picture.Graphic := bmp;
finally
bmp.Free;
end;
end;
```
上述代码中,我们首先将TImage中的图像复制到一个TBitmap对象中,然后调用StretchDraw方法实现旋转,最后将旋转后的图像显示在TImage中。这里我们使用StretchDraw方法实现旋转,参数中的Rect表示旋转后的图像位置和大小,第一个Rect中的Width和Height表示旋转后的图像大小,第二个Rect中的Width和Height表示旋转前的图像大小。