kadel Posted December 30, 2010 Share Posted December 30, 2010 Hello friends. Searching the forum found this code and works perfect. ; icon to JPEG & PNG converter - use first icon in EXE only ; based upon progandy's scripts ; ; nobbe 2008 ; #include <GDIPlus.au3> $filename = "C:\WINDOWS\explorer.exe" $iconnumber = 0 $Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$filename,"int*",$iconnumber) $hIcon = $Ret[0] _GDIPlus_Startup() $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0) $pBitmap = $pBitmap[2] _GDIPlus_ImageSaveToFile($pBitmap, @ScriptDir & "\Test.jpg") _GDIPlus_ImageSaveToFile($pBitmap, @ScriptDir & "\Test.png") _GDIPlus_ImageDispose($pBitmap) _GDIPlus_Shutdown() _WinAPI_DestroyIcon($Ret[0]) Someone can help me modify it to save the icons in 48 x 48 Pixel. From already thank you very much for helping. Link to comment Share on other sites More sharing options...
JohnOne Posted December 30, 2010 Share Posted December 30, 2010 What you want to do then is resize an image? Because if you search for 'resize image' you will find what you need. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
kadel Posted December 30, 2010 Author Share Posted December 30, 2010 Thanks for responding. But what I do is to directly extract icons 48 x 48 The code draws the 32 x 32 and look bad. Link to comment Share on other sites More sharing options...
Developers Jos Posted December 30, 2010 Developers Share Posted December 30, 2010 Thanks for responding.But what I do is to directly extract icons 48 x 48The code draws the 32 x 32 and look bad.Set this value to the correct one:$iconnumber = 0 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kadel Posted December 30, 2010 Author Share Posted December 30, 2010 Set this value to the correct one:$iconnumber = 0but this indicates the index of the icon ... not pixel Link to comment Share on other sites More sharing options...
Developers Jos Posted December 30, 2010 Developers Share Posted December 30, 2010 but this indicates the index of the icon ... not pixelcorrect... so find out the correct size icon and its index and you can extract the correct icon. Not aware of any other magic here. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kadel Posted December 31, 2010 Author Share Posted December 31, 2010 (edited) and how? I add the code to open the browser and all the icons are still keeping in 32 pixel .. and bad, with a black background $sFileName = @SystemDir & '\shell32.dll' ; Create a structure to store the icon index $stIcon = DllStructCreate("int") $stString = DLLStructCreate("wchar[260]") $structsize = DllStructGetSize($stString)/2 DllStructSetData($stString, 1, $sFileName) ; Run the PickIconDlg - '62' is the ordinal value for this function DllCall("shell32.dll", "none", 62, "hwnd", 0, "ptr", DllStructGetPtr($stString), "int", $structsize, "ptr", DllStructGetPtr($stIcon)) $sFileName = DllStructGetData($stString, 1) $nIconIndex = DllStructGetData($stIcon, 1) ; Show the new filename and icon index ;~ Msgbox(0, "Info", "Last selected file: " & $sFileName & @LF & "Icon-Index: " & $nIconIndex) $Ret = DllCall("shell32","long","ExtractAssociatedIcon","int",0,"str",$sFileName,"int*",$nIconIndex) $hIcon = $Ret[0] _GDIPlus_Startup() $pBitmap = DllCall($ghGDIPDll,"int","GdipCreateBitmapFromHICON", "ptr",$hIcon, "int*",0) $pBitmap = $pBitmap[2] _GDIPlus_ImageSaveToFile($pBitmap, @DesktopDir & "\test.png") _GDIPlus_ImageDispose($pBitmap) _GDIPlus_Shutdown() _WinAPI_DestroyIcon($Ret[0]) Any ideas how to solve this problem of black background and save them in 48 pixel ..? Edited December 31, 2010 by kadel Link to comment Share on other sites More sharing options...
Developers Jos Posted December 31, 2010 Developers Share Posted December 31, 2010 and how? Have a look with ResHacker to see which icons are stored in the PE resources. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
kadel Posted January 1, 2011 Author Share Posted January 1, 2011 Thanks for your answer but... We're not talking about using other programs, we are talking about the code of AutoIt. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 1, 2011 Developers Share Posted January 1, 2011 Thanks for your answer but...We're not talking about using other programs, we are talking about the code of AutoIt. Yes I understand, but you don't seem to understand that there is no magic here. A program will/can have a bunch on Icons stored in the PE header.Your initial posted code will extract the first ICON from the PE header and now you are asking what to do to extract the 48*48 version.The only way as far as I know is to find out which ICON that is yourself first and you can use Reshacker for that.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Yashied Posted January 1, 2011 Share Posted January 1, 2011 Any ideas how to solve this problem of black background and save them in 48 pixel ..? expandcollapse popup#Include <GDIPlus.au3> #Include <WinAPIEx.au3> ; Only for 32 bit (RGB + Alpha) icons! $sPng = @ScriptDir & '\Test.png' $sIco = @SystemDir & '\shell32.dll' $Index = 130 $W = 48 $H = 48 _GDIPlus_Startup() $hIcon = _WinAPI_ShellExtractIcon($sIco, $Index, $W, $H) $aInfo = _WinAPI_GetIconInfo($hIcon) $tBits = DllStructCreate('byte[' & (4 * $W * $H) & ']') $pBits = DllStructGetPtr($tBits) _WinAPI_GetBitmapBits($aInfo[5], DllStructGetSize($tBits), $pBits) $hBitmap = _GDIPlus_BitmapCreateFromScan0($W, $H, 4 * $W, $GDIP_PXF32ARGB, $pBits) _WinAPI_DestroyIcon($hIcon) For $i = 4 To 5 _WinAPI_DeleteObject($aInfo[$i]) Next _GDIPlus_ImageSaveToFile($hBitmap, $sPng) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0) Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipCreateBitmapFromScan0', 'int', $iWidth, 'int', $iHeight, 'int', $iStride, 'int', $iPixelFormat, 'ptr', $pScan0, 'ptr*', 0) If @error Then Return SetError(1, 0, 0) Else If $aResult[0] Then Return SetError($aResult[0], 0, 0) EndIf EndIf Return $aResult[6] EndFunc ;==>_GDIPlus_BitmapCreateFromScan0 My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Skitty Posted January 1, 2011 Share Posted January 1, 2011 Why do you wan't to extract these icons? You will most likely find these at iconfinder.com with full transparency already.. Any way this is pretty interesting, I'm trying to get these in there .ico format. Link to comment Share on other sites More sharing options...
kadel Posted January 1, 2011 Author Share Posted January 1, 2011 expandcollapse popup#Include <GDIPlus.au3> #Include <WinAPIEx.au3> ; Only for 32 bit (RGB + Alpha) icons! $sPng = @ScriptDir & '\Test.png' $sIco = @SystemDir & '\shell32.dll' $Index = 130 $W = 48 $H = 48 _GDIPlus_Startup() $hIcon = _WinAPI_ShellExtractIcon($sIco, $Index, $W, $H) $aInfo = _WinAPI_GetIconInfo($hIcon) $tBits = DllStructCreate('byte[' & (4 * $W * $H) & ']') $pBits = DllStructGetPtr($tBits) _WinAPI_GetBitmapBits($aInfo[5], DllStructGetSize($tBits), $pBits) $hBitmap = _GDIPlus_BitmapCreateFromScan0($W, $H, 4 * $W, $GDIP_PXF32ARGB, $pBits) _WinAPI_DestroyIcon($hIcon) For $i = 4 To 5 _WinAPI_DeleteObject($aInfo[$i]) Next _GDIPlus_ImageSaveToFile($hBitmap, $sPng) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = 0x0026200A, $pScan0 = 0) Local $aResult = DllCall($ghGDIPDll, 'uint', 'GdipCreateBitmapFromScan0', 'int', $iWidth, 'int', $iHeight, 'int', $iStride, 'int', $iPixelFormat, 'ptr', $pScan0, 'ptr*', 0) If @error Then Return SetError(1, 0, 0) Else If $aResult[0] Then Return SetError($aResult[0], 0, 0) EndIf EndIf Return $aResult[6] EndFunc ;==>_GDIPlus_BitmapCreateFromScan0 Wonderful script thank you very much for your help Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now