Jump to content
Sign in to follow this  
shx

Extract Icon into graphic file

Recommended Posts

shx

I'm trying to create a graphic file, by extracting an icon from an EXE in saving it as a JPEG

it seems to me that the steps are as follows.

• Get a handle of the icon that you wish to use.

• convert that somehow into a graphic image.

• Save the graphic to a file.

I understand that the method to use has to do with the GDI functions. However, if someone can give me an example of the steps, the code, it would really be appreciated. Thank you

The examples that I have found by searching the forum generally show how to use an icon within a GUI control.

I don't see how this would work for me. Thanks again

Steven

Share this post


Link to post
Share on other sites
shx

I'm trying to create a graphic file, by extracting an icon from an EXE in saving it as a JPEG

it seems to me that the steps are as follows.

" Get a handle of the icon that you wish to use.

" convert that somehow into a graphic image.

" Save the graphic to a file.

I understand that the method to use has to do with the GDI functions. However, if someone can give me an example of the steps, the code, it would really be appreciated. Thank you

The examples that I have found by searching the forum generally show how to use an icon within a GUI control.

I don't see how this would work for me. Thanks again

Steven

Share this post


Link to post
Share on other sites
Nahuel

You want to make an application to do that? or you want to do it just once?

If you want to do it just once, you could use 'reshack.exe'. It lets you save all the icons there is in an exe. Then use some image software to convert it to jpeg, like IrfanView.

Share this post


Link to post
Share on other sites
Kip

yeah, icons arent like bitmaps. Thats probably the reason why they gave them 2 different names.

Share this post


Link to post
Share on other sites
ProgAndy

You can extract with GDIPlus:

#include <GDIPlus.au3>
#include <IconChooser.au3> ;http://www.autoit.de/index.php?page=Thread&postID=31304#post31304

$Icon = _ChooseIcon()
If $Icon[0] = "" Then Exit MsgBox(0, 'Exit', "No Icon chosen")
$Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$Icon[0],"int*",(-1*$Icon[1])-1)
$hIcon = $Ret[0]
_GDIPlus_Startup()
        $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0)
        $pBitmap = $pBitmap[2]
_GDIPlus_ImageSaveToFile($pBitmap,"D:\Test.png")
_GDIPlus_ImageDispose($pBitmap)
_GDIPlus_Shutdown()
_WinAPI_DestroyIcon($Ret[0])
;~ MsgBox(0, "#" & $Icon[1], @error)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
shx

ProgAndy, Thanks for getting back to me and your help.

<IconChooser.au3> ;http://www.autoit.de/index.php?page=Thread&postID=31304#post31304

I clicked on the link but could not understand the German.

Where do I get the include file?

I'm kind of a newbie so please excuse if the answer is obvious.

Steven

Share this post


Link to post
Share on other sites
ProgAndy

The Include is in the Spoiler :) Click on "Anzeigen" to open it :( Then you can see "AutoIt-Quellcode"


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
shx

Look at nice similar example here

Thanks for your help.

This also was my post. Actually there was a problem with my browser and I ended up double posting. My apologies.

I don't understand where the include iconchooser.au3 is coming from.

You will nedd to use ExtracIconEx API to get icon from EXE file,

search forum for examples.

I did look at Extracticonex and I know it is used to create an array of handles for icons. That step I understand. But I am a beginner and there is very little in the help file or the forum that take those handles and use it to save the icon as a graphic file like a jpg or png.

Steven

Share this post


Link to post
Share on other sites
big_daddy

Merged topics

Share this post


Link to post
Share on other sites
shx

The Include is in the Spoiler :) Click on "Anzeigen" to open it :( Then you can see "AutoIt-Quellcode"

O.K.

I got it to run. Now I need to figure out what it is doing.

ProgAndy, your help is very much appreciated.

I'm a beginner so maybe my next question is obvious but when the file is saved as a png the background looks black. Why is that? does it have to do with transparency?

Steven

Share this post


Link to post
Share on other sites
ProgAndy

My Script consists out of 2 parts.

1) <IconChooser.au3> is a Dialog to Choose the Icon in a DLL :)

It Returns the negative Index number Starting with -1

2) ExtractAssociatedIcon loads the Icon to memory, but needs 0 based, positive Index, so I convert it ($index*(-1))-1) :)

GdipCreateBitmapFromHICON creates a GDIplus-Bitmap out of the Icon. The Transparency SHOULD be saved, too ( works for me)

Then the Image is saved with GDIplus as png, normally WITH transparecy.

How do you open the png? With MSPaint? This app doesn't support transparency. :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
shx

ProgAndy,

Thanks for your help and the time you took to explain things.

I have gotten it to work and it has helped me alot.

Steven :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×