mto*_*loo 2 delphi image imagelist transparent stretch
根据我在Cosmin Prund的帮助下的上一个问题,我找到了如何拉伸Image并添加到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;
Run Code Online (Sandbox Code Playgroud)
现在问题是插入的Image在ImageList中不透明.在TListview中显示项目时,图像不会透明.但是在正常添加图像时(没有拉伸和使用StretchedBMP变量)图像是透明的.
PS:上一个问题的链接是:在Delphi中将拉伸图像添加到ImageList
Rob*_*edy 10
您调用ImageList.Add并传递nil掩码图像.您可以计算与拉伸图像对应的蒙版,也可以调用ImageList.AddMasked图像列表,根据您指定为"透明"颜色的颜色为您计算蒙版.这就是在设计时使用图像列表组件编辑器时会发生的情况.
| 归档时间: |
|
| 查看次数: |
4062 次 |
| 最近记录: |