RSS订阅 | 匿名投稿
您的位置:网站首页 > 图像 > 正文

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

作者:admin 来源: 日期:2018/1/28 17:00:34 人气: 标签:ImageList

//向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;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址:
下一篇:没有资料