Jump to content

[Help] Get Icon 48x48


kadel
 Share

Recommended Posts

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

  • Developers

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.

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

  • Developers

but this indicates the index of the icon ... not pixel

correct... 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

and how? :x

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 by kadel
Link to comment
Share on other sites

  • Developers

Thanks for your answer but...

We're not talking about using other programs, we are talking about the code of AutoIt. :x

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

Any ideas how to solve this problem of black background and save them in 48 pixel ..?

#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

Link to comment
Share on other sites

#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 :x

thank you very much for your help :P

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...