有没有人知道一个可以读取多帧图标的类?在网上搜索并没有找到相关信息。
我尝试使用Alan Peter Stotz的IconTools 2.0,它可以正确地将图标加载到列表中,但8位和4位图标的位深度返回值为0。32位和24位图标帧的位深度返回值是正确的。
查看图标时,图标本身显示正确...只有提到的位深度是错误的。
编辑#2 根据TLama的评论,这里是一些未经测试的代码:
我尝试使用Alan Peter Stotz的IconTools 2.0,它可以正确地将图标加载到列表中,但8位和4位图标的位深度返回值为0。32位和24位图标帧的位深度返回值是正确的。
查看图标时,图标本身显示正确...只有提到的位深度是错误的。
编辑#2 根据TLama的评论,这里是一些未经测试的代码:
function NumberOfIcons ( AFileName: string ): integer;
var
iNumberOfIcons: Integer;
begin
iNumberOfIcons := ExtractIcon ( hInstance, PChar ( AFilename ), UINT ( -1 ) );
Result := iNumberOfIcons;
end;
function ExtractAnIcon ( AFilename: string; AIndex: integer ): TBitmap;
var
icoHandle: HIcon;
iBitmap: TBitmap;
iIcon: TIcon;
iNumberOfIcons, i: Integer;
begin
Result := nil;
iBitmap := TBitMap.Create;
iIcon := TIcon.Create;
try
// Get the number of Icons
iNumberOfIcons := ExtractIcon ( hInstance, PChar ( AFilename ), UINT ( -1 ) );
// Extract the icon frame
icoHandle := ExtractIcon ( hInstance, PChar ( AFileName ), AIndex );
iIcon.Handle := icoHandle;
iBitmap.Width := iIcon.Width;
iBitmap.Height := iIcon.Height;
// Draw the icon on your bitmap
DrawIcon ( iBitmap.Canvas.Handle, 0, 0, iIcon.Handle );
Result := iBitmap;
finally
iIcon.Free;
end;
end;
function PixelFormatToBitDepth ( APixelFormat: TPixelFormat ): integer;
// Convert TPixelFormat to integer
begin
Result := -1;
case APixelFormat of
pf32Bit:
Result := 32;
pf24bit:
Result := 24;
pf8bit:
Result := 8;
pf4Bit:
Result := 4;
pf1bit:
Result := 1;
end;
end;
我是否走在正确的轨道上?在我的测试中,我现在得到了1个图标,但是NumberOfIcons函数返回1吗?
编辑#3 根据帮助文件,“如果文件是.ico文件,则ExtractIcon的返回值为1。”那么有什么方法可以用来获取ico文件中的图标数量?