问题描述
根据我以前的问题,在Cosmin Prund的帮助下,我发现如何拉伸图像并添加到ImageList:过程LoadDatasetImagesToImageList;
var
StretchedBMP:TBitmap;
MS:TMemoryStream;
begin
ImageList.Clear;
ItemsDts.First;
StretchedBMP:= TBitmap.Create;
try
//准备拉伸的bmp的大小
StretchedBMP.Width:= ImageList.Width;
StretchedBMP.Height:= ImageList.Height;
//准备内存流
MS:= TMemoryStream.Create;
try
ImageBitmap:= TBitmap.Create;
尝试
而不是ItemsDts.Eof做
开始
如果不是ItemsDtsPicture.IsNull然后
开始
MS.Size:= 0;
ItemsDtsPicture.SaveToStream(MS);
MS.Position:= 0;
ImageBitmap.LoadFromStream(MS)
//伸展图像
StretchedBMP.Canvas.StretchDraw(Rect(0,0,StretchedBmp.Width-1,StretchedBmp.Height-1),ImageBitmap);
ImageList.Add(StretchedBmp,nil);
结束
ItemsDts.Next;
结束
finally
ImageBitmap.Free;
结束
finally
MS.Free;
结束
finally
StretchedBMP.Free;
结束
现在的问题是插入的图像在ImageList中不透明。在TListview中显示项目时,图像不会透明。
但是当正常添加图像(没有拉伸和使用StretchedBMP变量)图像是透明的。
PS:上一个问题的链接是:
您调用 ImageList.Add
并通过 nil
掩模图像。您可以计算对应于您的拉伸图像的蒙版,也可以调用,以使图像列表根据您指定为透明颜色的颜色为您计算一个蒙版。当您在设计时使用图像列表组件编辑器时,会发生什么。
According to my previous question with the help of Cosmin Prund, I found how to stretch Image and add to 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;
Now the problem is that inserted Image is not transparent in ImageList. When displaying Items in a TListview, images are not transparented.But when adding images normally (without stretching and using StretchedBMP variable) images are transparent.
PS: the link to the previous question is: Add stretched image to ImageList in Delphi
You call ImageList.Add
and pass nil
for the mask image. You can either calculate the mask corresponding to your stretched image, or you can call ImageList.AddMasked
instead to have the image list calculate a mask for you based on a color that you designate as the "transparent" color. That's what happens when you use the image-list component editor at design time.
这篇关于在Delphi中添加透明和拉伸图像到Imagelist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!