ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Perfect method for extracting main icon from EXE?
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

PeterPanino

935 Posts

Posted - Mar 13 2016 :  17:16:48  Show Profile  Reply
I've tried for several hours now, but couldn't get a 100% working and foolproof method to extract the main icon (group) from ANY .EXE file and save it as an .ICO file.

Can anybody help?

w2m

USA
1990 Posts

Posted - Mar 13 2016 :  17:52:19  Show Profile  Reply
Give the Resource Extractor demo here: http://www.imageen.com/demos/index.html

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

PeterPanino

935 Posts

Posted - Mar 13 2016 :  18:15:19  Show Profile  Reply
Unfortunately, it does not work with this EXE (see attached file).

attach/PeterPanino/2016313181425_BabelPad.zip
3337.64 KB
Go to Top of Page

xequte

38690 Posts

Posted - Mar 13 2016 :  22:33:33  Show Profile  Reply
Hi Peter

Worked fine in my testing (Using the \InputOutput\ResourceLoader demo).



Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

PeterPanino

935 Posts

Posted - Mar 14 2016 :  04:12:09  Show Profile  Reply
You mentioned Resource Extractor, not ResourceLoader.

ResourceLoader shows the icons and Resource Extractor saves the Icon Group.

\ImageEn\Demos\FullApps\ResourceExtractor

As I mentioned in my question, I need to SAVE the main icon, not just to show it.
Go to Top of Page

PeterPanino

935 Posts

Posted - Mar 14 2016 :  06:29:05  Show Profile  Reply
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?
Go to Top of Page

w2m

USA
1990 Posts

Posted - Mar 14 2016 :  13:28:27  Show Profile  Reply
I have Axialis IconWorkshop and when I view attach/PeterPanino/20163147846_ExtractedIcon0.zip there are no RGBA 32-bit frames. Here IconWorkShop displays 32bit icons with a white background and all other color depths with a black background.

If you are loading the icons in TImageEnView set the background color to White.

Also if you post your demo source code I can investigate this further. But I believe ImageEn itself is operating as expected as best as I can tell.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: