image - 在 Delphi 中将透明和拉伸(stretch)图像添加到图像列表

标签 image delphi transparent stretch imagelist

根据我之前在 Cosmin Prund 的帮助下提出的问题,我找到了如何拉伸(stretch)图像并添加到 ImageList:

procedure LoadDatasetImagesToImageList;
var 
  StretchedBMP: TBitmap;
  MS: TMemoryStream;
begin
  ImageList.Clear;
  ItemsDts.First;
  StretchedBMP := TBitmap.Create;
try

  // Prepare the stretched bmp's size
  StretchedBMP.Width := ImageList.Width;
  StretchedBMP.Height := ImageList.Height;

  // Prepare the memory stream
  MS := TMemoryStream.Create;
  try
    ImageBitmap:= TBitmap.Create;
    try
      while not ItemsDts.Eof do
      begin
        if not ItemsDtsPicture.IsNull then
        begin
          MS.Size := 0;
          ItemsDtsPicture.SaveToStream(MS);
          MS.Position := 0;
          ImageBitmap.LoadFromStream(MS);
          // Stretch the image
          StretchedBMP.Canvas.StretchDraw(Rect(0, 0, StretchedBmp.Width-1, StretchedBmp.Height-1), ImageBitmap);
          ImageList.Add(StretchedBmp, nil);
        end;
        ItemsDts.Next;
      end;
    finally 
      ImageBitmap.Free;
    end;
  finally 
    MS.Free;
  end;
finally
  StretchedBMP.Free;
end;

现在的问题是插入的Image在ImageList中是不透明的。在 TListview 中显示项目时,图像不透明。 但是当正常添加图像时(不拉伸(stretch)和使用 StretchedBMP 变量)图像是透明的。

PS:上一个问题的链接是:Add stretched image to ImageList in Delphi

最佳答案

您调用 ImageList.Add 并为蒙版图像传递 nil。您可以计算与拉伸(stretch)图像对应的掩码,也可以调用 ImageList.AddMasked而不是让图像列表根据您指定为“透明”颜色的颜色为您计算蒙版。这就是在设计时使用图像列表组件编辑器时发生的情况。

关于image - 在 Delphi 中将透明和拉伸(stretch)图像添加到图像列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6688356/

相关文章:

javascript - 在 ReactJS 上显示图像

相同内容但不同天气的图像相似性

html - 在 IE9 中作为链接的图片

delphi - 如何使用TPrinter的本地实例

delphi - 将 dbgrid 中的数据输入到 word 邮件合并中

swift |检测碰撞时忽略 Sprite 的透明部分?

c++ - 如何阻止 LWA_COLORKEY 绘制灰色轮廓?

html - 响应式,百分比图像差距问题

delphi - 在 Delphi 7 中制作 TPageControl 平面

html - 点击透明.png