GdiPlus[51]: 图像(三) 关于呈现

本文介绍使用GDI+进行图像处理的方法,包括如何绘制图像、生成略缩图及旋转翻转等操作。演示了指定宽度和高度绘制图像的重要性,并展示了通过不同参数实现图像的多种旋转效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


相关方法:
IGPGraphics.DrawImage();
IGPImage.GetThumbnailImage();
IGPImage.RotateFlip();

用 DrawImage 呈现图像时, 是否指定 Width 和 Height 的区别:

o_09122801.png

//如果图像的分辨率与 Graphics 的分辨率不一致, 则指定 Width、Height 是有必要的.
uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Image: IGPImage;
  ix,iy,gx,gy: Single;
begin
  Image := TGPImage.Create('C:\GdiPlusImg\Shapes.bmp');
  Graphics := TGPGraphics.Create(Handle);

  Graphics.DrawImage(Image, 10, 10, Image.Width, Image.Height);
  Graphics.DrawImage(Image, Image.Width + 20, 10);

  ix := Image.HorizontalResolution;
  iy := Image.VerticalResolution;
  gx := Graphics.DpiX;
  gy := Graphics.DpiY;
  Text := Format('%.0f:%.0f; %.0f:%.0f', [ix, iy, gx, gy]);
end;

略缩图:

o_09122802.png

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Thumbnail,Image: IGPImage;
begin
  Image := TGPImage.Create('C:\GdiPlusImg\Apple.gif');
  Thumbnail := Image.GetThumbnailImage(32, 32);
  
  Graphics := TGPGraphics.Create(Handle);
  Graphics.DrawImage(Image, 0, 0, Image.Width, Image.Height);
  Graphics.DrawImage(Thumbnail, Image.Width + 2, 0, Thumbnail.Width, Thumbnail.Height);
end;

图像旋转:

o_09122803.png

uses GdiPlus;

procedure TForm1.FormPaint(Sender: TObject);
var
  Graphics: IGPGraphics;
  Image,ImageClone: IGPImage;
  i: Integer;
begin
  Image := TGPImage.Create('C:\GdiPlusImg\Bird.bmp');
  Graphics := TGPGraphics.Create(Handle);

  for i := 0 to 7 do
  begin
    ImageClone := Image.Clone;
    ImageClone.RotateFlip(TGPRotateFlipType(i));
    Graphics.DrawImage(ImageClone, 10, 10, Image.Width, Image.Height);
    Graphics.TranslateTransform(Image.Width + 10, 0);
    if i = 3 then
    begin
      Graphics.TranslateTransform(-Graphics.Transform.OffsetX, Image.Height + 10);
    end;
  end;
end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值