So the problem is now solved:
procedure TForm1.LoadSingleFrameFromMultiFrameFiles;
procedure LoadLargestFrameFromIco(const aIcoFile: string);
var
B: TIEBitmap;
P: TIOParams;
LargestFrame, LargestFrameIndex, WxH, FrameCount: Integer;
i: Integer;
ThisImage: Integer;
begin
B := TIEBitmap.Create;
P := TIOParams.Create;
try
if P.Read(aIcoFile) then
begin
LargestFrameIndex := 0;
FrameCount := P.ImageCount;
if FrameCount > 1 then
begin
LargestFrame := 0;
for i := 0 to FrameCount - 1 do
begin
WxH := P.ICO_Sizes[i].Width * P.ICO_Sizes[i].Height;
if WxH > LargestFrame then
begin
LargestFrame := WxH;
LargestFrameIndex := i;
end;
end;
end;
P.ImageIndex := LargestFrameIndex;
B.Read(aIcoFile, P);
ThisImage := mimgTest.AppendImage();
mimgTest.SetImage(ThisImage, B);
mimgTest.ImageTopText[ThisImage] := ExtractFileName(aIcoFile) + ' (Frame #' + IntToStr(LargestFrameIndex + 1) + '/' + IntToStr(P.ImageCount) + ')';
mimgTest.ImageInfoText[ThisImage] := IntToStr(B.Width) + ' x ' + IntToStr(B.Height);
FImagePaths.Add(aIcoFile);
end;
finally
P.Free;
B.Free;
end;
end;
procedure LoadImage(const aImageFile: string);
var
P: TIOParams;
ThisImage, FrameCount: Integer;
ThisTopText: string;
begin
P := TIOParams.Create;
try
if P.Read(aImageFile) then
begin
FrameCount := P.ImageCount;
if FrameCount = 1 then
ThisTopText := ExtractFileName(aImageFile)
else if FrameCount > 1 then
ThisTopText := ExtractFileName(aImageFile) + ' (' + IntToStr(FrameCount) + ' frames)';
ThisImage := mimgTest.AppendImage(aImageFile);
mimgTest.ImageTopText[ThisImage] := ThisTopText;
mimgTest.ImageInfoText[ThisImage] := IntToStr(mimgTest.ImageWidth[ThisImage]) + ' x ' + IntToStr(mimgTest.ImageHeight[ThisImage]);
FImagePaths.Add(aImageFile);
end;
finally
P.Free;
end;
end;
begin
// ICO containing multiple frames:
LoadLargestFrameFromIco('C:\DELPHI\_test\MIOLoadFirstFrame\TestIcon1.ico');
// GIF:
LoadImage('C:\DELPHI\_test\MIOLoadFirstFrame\TestGIF1.gif');
// TIF:
LoadImage('C:\DELPHI\_test\MIOLoadFirstFrame\TestTIFMulti.tif');
// PNG:
LoadImage('C:\DELPHI\_test\MIOLoadFirstFrame\flowers.png');
// ICO containing only 1 frame:
LoadLargestFrameFromIco('C:\DELPHI\_test\MIOLoadFirstFrame\Testicon2.ico');
mimgTest.SelectedImage := 0;
ShowFilePathInStatusBar(0);
end;

Here is the whole project, so you can test it in Delphi:
attach/PeterPanino/2021527165118_MIOLoadFirstFrame_v3.zip
737.9 KB