ben*_*ben 6 delphi icons imagelist
我花了几个小时来完成这个(简单的)并且找不到解决方案:/
我正在使用D7和TImageList.ImageList被分配给工具栏.当我在设计时填充ImageList时,图标(具有部分透明度)看起来很好.但我需要在运行时填充它,当我这样做时,图标看起来很糟糕 - 完全松散了部分透明度.
我只是尝试从.res文件中加载图标 - 结果相同.我尝试过第三方图像列表也没有成功.我不知道我能做什么:/谢谢2所有;)
编辑:
说实话,我不知道到底发生了什么.Alpha混合是相关术语......这里有两个屏幕:
在设计时添加的图标: 替代文字http://shs-it.de/tmp/icon-designtime.JPG
在运行时添加的图标: 替代文字http://shs-it.de/tmp/icon-runtime.JPG
您不支持Alpha混合的评论带来了解决方案:我在编辑器中编辑了图像并删除了"alpha混合"像素 - 现在它看起来很好.但是,在运行时添加图标而不是设计时,图标看起来仍然很奇怪.如果你(或其他人)可以解释它,我会很高兴;)感谢您的支持!
要支持Alpha透明度,您需要创建图像列表并在运行时填充它:
function AddIconFromResource(ImageList: TImageList; ResID: Integer): Integer;
var
Icon: TIcon;
begin
Icon := TIcon.Create;
try
Icon.LoadFromResourceID(HInstance, ResID);
Result := ImageList.AddIcon(Icon);
finally
Icon.Free;
end;
end;
function AddPngFromResource(ImageList: TImageList; ResID: Integer): Integer;
var
Png: TPngGraphic;
ResStream: TStream;
Bitmap: TBitmap;
begin
ResStream := nil;
Png := nil;
Bitmap := nil;
try
ResStream := TResourceStream.CreateFromID(HInstance, ResID, RT_RCDATA);
Png := TPNGGraphic.Create;
Png.LoadFromStream(ResStream);
FreeAndNil(ResStream);
Bitmap := TBitmap.Create;
Bitmap.Assign(Png);
FreeAndNil(Png);
Result := ImageList.Add(Bitmap, nil);
finally
Bitmap.Free;
ResStream.Free;
Png.Free;
end;
end;
// this could be e.g. in the form's or datamodule's OnCreate event
begin
// create the imagelist
ImageList := TImageList.Create(Self);
ImageList.Name := 'ImageList';
ImageList.DrawingStyle := dsTransparent;
ImageList.Handle := ImageList_Create(ImageList.Width, ImageList.Height, ILC_COLOR32 or ILC_MASK, 0, ImageList.AllocBy);
// populate the imagelist with png images from resources
AddPngFromResource(ImageList, ...);
// or icons
AddIconFromResource(ImageList, ...);
end;
Run Code Online (Sandbox Code Playgroud)
几年前我遇到了完全相同的问题。这是德尔福的问题。我最终在设计时将图像放入列表中,尽管我真的不想这么做。我还必须使用 DevExpress 图像列表来获得最佳结果并使用 32 位彩色图像。