Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to extract image from a header and display in a TImage?

Status
Not open for further replies.

Ante0

Programmer
Apr 19, 2007
98
SE
Is it possible to extract an image(Icon) from a Header in an exe and place it in a TImage in your application?
I know the image is located at 0x68, but I have no idea how to go any further...
Thanks for any help :)
 
you mean like the application icon?

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
You mean something like this?

Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  h : THandle;
  Icon : HIcon;
begin
  h := LoadLibrary('icontable.dll');
  try
    if h <> 0 then
    begin
      Icon := LoadIcon(h, 'Icon1');
      DrawIcon(Canvas.Handle, 10, 10, Icon);
    end
    else
    begin
      ShowMessage('Load Resource DLL FAILED!');
    end;
  finally
    FreeLibrary(h);
  end;
end;

Resource Hacker in the additional tools thread will be useful to you to figure out the proper reference name for the icon.
 
No, It's an image that resides inside the Exe.
And I've tried with ResHacker, just gives me an error when I try to open the exe.

I'm fairy sure this can be a bit hard...
Lets say you have a BitBtn placed on a form, and that button has an Icon loaded on it, and you can't view it in ResHacker... How would you go by to get the image to show in a TImage in another application?
 
Lets say you have a BitBtn placed on a form, and that button has an Icon loaded on it, and you can't view it in ResHacker... How would you go by to get the image to show in a TImage in another application?

This is different than an icon resource. You will in browsing the resources that the image on a BitBtn is not stored as a image resource, but as a glyph within the form definition. To save trouble, you can open up the form definition with a text file reader (it's the *.DFM files) and look at them.

So your question is how to extract and interpret a glyph from a form definition as to show it on a TImage. I have no concrete clue how to do this, but I would begin by trying to interpret the values for the glyph into pixel color values and then draw them to the TImage. I would suggest testing on the DFM file to start and once you get it worked out you can move on to loading the form definition (it's similar code to what I posted).

(I was able to load executables from both Delphi 3 and Turbo Delphi 2006 in Resource Hacker, perhaps it's an access issue?)

(as another off-topic thought, it's almost always a shame so many interesting things to try come up in forums like this - I already got such a backlog of "hobby" projects I could be doing that I could work full-time at them if I had the means. Anyhow this sounds like a fun project, good luck on it :) )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top