Anyway, now I have generalized the extraction of icons:
procedure TForm1.SaveResourceIcons(const AResourceFile, AExtrIconFile: string);
var
i: integer;
j: integer;
k: integer;
iResourceExtractor: TIEResourceExtractor;
iFrames: array of TObject;
iBuffer: Pointer;
iBufferLen: integer;
iFileToSave: string;
iGroupFrameWidth: integer;
iGroupFrameHeight: integer;
begin
iResourceExtractor := TIEResourceExtractor.Create(AResourceFile);
try
if iResourceExtractor.IsValid then
begin
// search for GroupIcon, loop among Types:
for i := 0 to iResourceExtractor.TypesCount - 1 do
begin
//CodeSite.Send('iResourceExtractor.Types[i]', iResourceExtractor.Types[i]);
if iResourceExtractor.FriendlyTypes[i] = 'GroupIcon' then
begin
//CodeSite.Send('iResourceExtractor.FriendlyTypes[i] = GroupIcon');
// GroupIcon found, loop among Names
for j := 0 to iResourceExtractor.NamesCount[i] - 1 do
begin
// Allocate array of TImageEnView objects and load frames
SetLength(iFrames, iResourceExtractor.GroupCountFrames[i, j]);
for k := 0 to length(iFrames) - 1 do
begin
iBuffer := iResourceExtractor.GetFrameBuffer(i, j, k, iBufferLen);
iFrames[k] := TImageEnView.Create(nil);
iGroupFrameWidth := iResourceExtractor.GroupFrameWidth[i, j, k];
iGroupFrameHeight := iResourceExtractor.GroupFrameHeight[i, j, k];
(iFrames[k] as TImageEnView).IO.Params.IsResource := True;
(iFrames[k] as TImageEnView).IO.LoadFromBuffer(iBuffer, iBufferLen, ioICO);
(iFrames[k] as TImageEnView).IO.Params.ICO_Sizes[k].cx := iGroupFrameWidth;
(iFrames[k] as TImageEnView).IO.Params.ICO_Sizes[k].cY := iGroupFrameHeight;
(iFrames[k] as TImageEnView).IO.Params.ICO_BitCount[k] := (iFrames[k] as TImageEnView).IO.Params.SamplesPerPixel *
(iFrames[k] as TImageEnView).IO.Params.BitsPerSample;
end;
// Create Multiframe ICO
iFileToSave := AExtrIconFile + IntToStr(j) + '.ico';
IEWriteICOImages(iFileToSave, iFrames);
// Cleanup Frames
for k := 0 to length(iFrames) - 1 do
iFrames[k].Free();
end;
end;
end;
end;
finally
iResourceExtractor.Free;
end;
end;
// usage:
SaveResourceIcons(Trim(Edit1.Text), 'R:\ExtractedIcon');
However, there seems to be an issue with the extracted icons (see attachment):
This is how the icons look when DriveLetterView.exe is directly opened in Axialis IconWorkshop:
And this is how the icons EXTRACTED with the above procedure look in Axialis IconWorkshop:
You can see from the BLACK background in the EXTRACTED icons that there is something wrong with them, as this would make icons with a black content unrecognizable.
attach/PeterPanino/201631463152_extract_icons.zip
147.28 KB
You can also see that the icon extracted from another exe (EssentialPIM.exe) that the RGB/A (32bit with AlphaTransparency) images in the extracted icon are just fine, while the 256 color (8 bit) images have this black background color:
attach/PeterPanino/20163147846_ExtractedIcon0.zip
59.41 KB
So how can this black background be avoided?