delphi向ImageList中加入png类型的资源图片


本文整理自网络,侵删。

 
//向ImageList中加入png类型的资源图片
procedure AddPngToImageList(AImageList: TImagelist; AResName: string);
var
  LResStream: TStream;
  LPng: TPngImage;
  LBitMap, LRowBitMap: TBitmap;
  LRect, LRowRect: TRect;
begin
  //AImageList.DrawingStyle := dsTransparent;
  AImageList.ColorDepth := cd32Bit;
  LResStream := TResourceStream.Create(uResourcesImpl.GetResHandle, AResName, RT_RCDATA);
  LPng := TPngImage.Create;
  LBitMap := TBitmap.Create;
  try
    LPng.LoadFromStream(LResStream);
    LBitMap.Assign(LPng);
    LBitMap.AlphaFormat := afIgnored;
    if LBitMap.Height > AImageList.Height then
    begin
      LRowBitMap := TBitmap.Create;
      try
        LRowBitMap.Width := LBitMap.Width;
        LRowBitMap.Height := AImageList.Height;
        LRect := Rect(0, 0, LBitMap.Width, LRowBitMap.Height);
        LRowRect := Rect(0, 0, LRowBitMap.Width, LRowBitMap.Height);
        while LRect.Bottom <= LBitMap.Height do
        begin
          LRowBitMap.Canvas.CopyRect(LRowRect, LBitMap.Canvas, LRect);
          OffsetRect(LRect, 0, LRowBitMap.Height);
          AImageList.Add(LRowBitMap, nil);
        end;
      finally
        LRowBitMap.Free;
      end;
    end
    else
      AImageList.Add(LBitMap, nil);
  finally
    LResStream.Free;
    LPng.Free;
    LBitMap.Free;
  end;
end;

相关阅读 >>

Delphi idmessage1 idsmtp1 发送邮件支持https

Delphi 从dbgird中导出到excel

Delphi常用获取系统信息的函数单元

Delphi winapi: flashwindow - 闪烁窗口

Delphi 调用外部 dll 中的函数(1. 早绑定)

Delphi 语法基础: 使用不同的数据类型标记数组

Delphi使用indy组件http上传文件

Delphi 实现无标题栏但有边框的窗口

Delphi10及以上版本安装activex控件

Delphi wm_copydata 用法

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...