随笔 - 2146  文章 - 19 评论 - 11846 阅读 - 1267万


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


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



//如果图像的分辨率与 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;


略缩图:



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;


图像旋转:



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;

posted on   万一  阅读(4475)  评论(7编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
历史上的今天:
2007-12-28 判断两个字符串是否相似的函数 AnsiResemblesText 专题研究
2007-12-28 Delphi 中的字符串函数(6) - StrUtils 中的 Ansi 字符串函数
2007-12-28 Delphi 中的字符串函数(5) - SysUtils 中的 Ansi 字符串函数
2007-12-28 System 中的数学函数
2007-12-28 Math 中常用的数学函数
2007-12-28 返回整数的四种情况


点击右上角即可分享
微信分享提示