Jpg zu ico

  • Hi Leute ich brauch mal wieder eure Hilfe, undzwar suche ich eine function die mir jpg files in ico files convertiert.
    Hab schon n bissel rumprobiert mit GDIPLUS aber es will nicht so wie ich es will??

    Spoiler anzeigen
    [autoit]

    #Include <GUIConstantsEx.au3>
    #include <GDIPLUS.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Global Const $sJpg = @ScriptDir&"\Test.jpg",$output = @ScriptDir&"\test.ico"
    If Not FileExists($sJpg) Then Exit

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUICreate('Example1', 204, 108)
    $Icon1 = GUICtrlCreateIcon("", 0, 30, 38, 32, 32)
    _GDIPlus_StartUp()
    $hImage = _GDIPlus_ImageLoadFromFile($sJpg)
    $sCLSID = _GDIPlus_EncodersGetCLSID("ICO")
    _GDIPlus_ImageSaveToFile($hImage,$output)
    _GDIPlus_ShutDown()
    GUICtrlSetImage($Icon1,$output)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit] [autoit][/autoit] [autoit]

    GUIDelete()

    [/autoit]
  • habs selbst Herrausgefunden.
    Ich hab mir von diser Seite: http://www.daolnwod.com/imgcnvrt-dll--…verter-dll.html
    die ImageConverter.dll gedownloadet und folgende funktion geschrieben.

    Spoiler anzeigen
    [autoit]

    Func _img_converter($input,$output)
    $open=DllOpen("ImageConverter.dll")
    DllCall($open,"int","ConvertImage","wstr",$input,"wstr",$output,"int",0,"int",0,"int",0,"int",0,"int",0,"int",0)
    DllClose($open)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    _img_converter(@ScriptDir&"\Albumart.jpg",@ScriptDir&"\test.ico")

    [/autoit]

    Funktioniert einmanfrei :D

    INPUT

    Spoiler anzeigen

    Bitmaps: BMP,DIB,RLE
    CompuServe GIF: GIF
    JPEGs: JPG,JPEG,JPE,JFIF,JIF
    JPEG2000: JP2
    Photodhop: PSD
    Portable Bitmaps: PBM,PGM,PPM,PXM
    Portable Network Graphics: PNG
    Targa: TGA,VDA,ICB,VST
    TIFFs: TIF,TIFF,FAX,G3N,G3F
    Windows Cursor: CUR
    Windows Enhanced Metafile: EMF
    Windows Icon: ICO
    Windows Metafile: WMF
    Wireless Bitmap: WBMP
    ZSoft Paintbrush: PCX,DCX

    Output

    Spoiler anzeigen

    Adobe Acrobat: PDF
    Bitmaps: BMP
    CompuServe GIF: GIF
    JPEGs: JPG, JPEG
    JPEG2000: JP2
    Portable Bitmaps: PXM
    Portable Network Graphics: PNG
    Targa: TGA
    TIFFs: TIF, TIFF
    Windows Icon: ICO
    Wireless Bitmap: WBMP
    ZSoft Paintbrush: PCX,DCX

  • Ich hab hier mal ein kleines Beispiel mit einer Funktion aus dem englischen Forum gebastelt.

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hBitmap = _GDIPlus_BitmapCreateFromFile(FileOpenDialog("Bild auswählen", @UserProfileDir, "Bilder (*.*)"))
    $hIcon = _GDIPlus_HICONCreateFromBitmap($hBitmap)

    [/autoit] [autoit][/autoit] [autoit]

    _CreateIconFileFromHICON($hIcon, StringRegExpReplace(FileSaveDialog("Speichern unter", @ScriptDir, "Icons (*.ico)"), "(?:.*)(\..*\b)", ".ico"))

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_DestroyIcon($hIcon)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    Func _CreateIconFileFromHICON($HICON, $sOutIcon)
    Local $aInfo, $sIco, $sBmp, $hCDC, $tBI, $tBits, $iSz, $sBD, $FO

    [/autoit] [autoit][/autoit] [autoit]

    ; Start of single icon Header 3 x 2 bytes = 6 bytes: 0000 Reserved / 0100 icon / 0100 Numer of icons, total length will be 22 bytes for a single icon when finished
    $sIco = "0x000001000100"

    [/autoit] [autoit][/autoit] [autoit]

    ; Start of the Bitmap data header 1 x 4bytes: length of the header will be 40 bytes when finished. Will be appended to the end of the icon header when finished
    $sBmp = "28000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; Get info about the HICON, this is mainly to get the pointers to the Color/Mask bitmaps data
    $aInfo = _WinAPI_GetIconInfo($HICON)

    [/autoit] [autoit][/autoit] [autoit]

    ; create a memory Compatable DC
    $hCDC = _WinAPI_CreateCompatibleDC(0)

    [/autoit] [autoit][/autoit] [autoit]

    ; create a BITMAPINFO Struct to store the Bitmap Info, it needs to be inilialized by setting the struct size.
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))

    [/autoit] [autoit][/autoit] [autoit]

    ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the color bitmap data, we use it to write the headers
    _WinAPI_GetDIBits($hCDC, $aInfo[5], 0, 0, 0, DllStructGetPtr($tBI), 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; Now we have some the basic info to add to the icon & Bitmap header so we'll add that to the headers.
    $sIco &= Hex(DllStructGetData($tBI, "Width"), 2) & Hex(DllStructGetData($tBI, "Height"), 2) & "00000100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4))
    $sBmp &= _RB(Hex(DllStructGetData($tBI, "Width"))) & _RB(Hex(DllStructGetData($tBI, "Height") * 2)) & "0100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) & "00000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the size of the Bitmap data from the BITMAPINFO Struct, we'll use this in the headers further on.
    $iSz = DllStructGetData($tBI, "SizeImage")

    [/autoit] [autoit][/autoit] [autoit]

    ; create a struct to store the Bitmap data Bits of the first bitmap, reset the BITMAPINFO struct
    $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the color bitmap dib bits into the $tBits struct.
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[5], 'int', $iSz, 'ptr', DllStructGetPtr($tBits))

    [/autoit] [autoit][/autoit] [autoit]

    ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to Top to Bottom dib ;)
    ; ATM I'm only assuming that GetBitmapBits returns a Bottom to Top dib, maybe the bitmap bits you use could be Top Down already?.
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
    $sBD &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ;Clear the BITMAPINFO & $tBits Struct as we'll use the same variables again for the mask bitmap data
    $tBits = 0
    $tBI = 0

    [/autoit] [autoit][/autoit] [autoit]

    ; create a BITMAPINFO Struct to store the Bitmap Info again, it needs to be inilialized by setting the struct size.
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))

    [/autoit] [autoit][/autoit] [autoit]

    ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the bitmask bitmap data
    _WinAPI_GetDIBits($hCDC, $aInfo[4], 0, 0, 0, DllStructGetPtr($tBI), 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; We've finished with the Compatable DC, delete it.
    _WinAPI_DeleteDC($hCDC)

    [/autoit] [autoit][/autoit] [autoit]

    ; Add the size of the of the color + bitmask bitmap data as we need this for both the icon & Bitmap header
    $iSz += DllStructGetData($tBI, "SizeImage")

    [/autoit] [autoit][/autoit] [autoit]

    ; combine the bitmap data size with the bitmap header, I'm padding the rest of the 40 byte bitmap header with 0's., that's the Bitmap header done
    $sBmp &= _RB(Hex($iSz)) & "00000000000000000000000000000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; Now add the size of the Bitmap data + bitmap header size and combine the icon header together with the bitmap header and color bitmap data
    $sIco &= _RB(Hex($iSz + 40)) & _RB(Hex("22")) & $sBmp & $sBD

    [/autoit] [autoit][/autoit] [autoit]

    ; create a struct to store the Bitmap dib Bits of the mask bitmap
    $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the mask bitmap dib bits into the $tBits struct.
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[4], 'int', DllStructGetData($tBI, "SizeImage"), 'ptr', DllStructGetPtr($tBits))

    [/autoit] [autoit][/autoit] [autoit]

    ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to a Top to Bottom dib and append the mask bitmap data to the icon
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
    $sIco &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; Write the icon to a file.
    $FO = FileOpen($sOutIcon, 18)
    FileWrite($sOutIcon, Binary($sIco))
    FileClose($FO)

    [/autoit] [autoit][/autoit] [autoit]

    ; Clear the structs
    $tBits = 0
    $tBI = 0
    EndFunc ;==>_CreateIconFileFromHICON

    [/autoit] [autoit][/autoit] [autoit]

    ; Reverse Byte String
    Func _RB($sByte)
    Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = ''
    For $i = UBound($aX) - 1 To 0 Step -1
    $sX &= $aX[$i]
    Next
    Return $sX
    EndFunc ;==>_RB

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_HICONCreateFromBitmap($hBitmap)
    Local $HICON

    [/autoit] [autoit][/autoit] [autoit]

    $HICON = DllCall($ghGDIPDll, "int", "GdipCreateHICONFromBitmap", "hwnd", $hBitmap, "int*", 0)
    If @error Then Return SetError(@error, 0, -1)
    Return SetError($HICON[0], 0, $HICON[2])
    EndFunc ;==>_GDIPlus_BitmapCreateHICONFromBitmap

    [/autoit]


    Funktioniert bei mir problemlos. :)

  • name22 was schneller!

    Hier im Prinzip die gleiche Funktion von smashly, aber mit einer Resize Funktion:

    Spoiler anzeigen
    [autoit]


    #include <GDIPlus.au3>
    #include <WinAPI.au3>
    $file = FileOpenDialog("Ein Bild auswählen", "", "Bilder (*.jpg;*.bmp;*.png)")
    If @error Then Exit

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup ()
    $bild = Resize($file)
    $hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($bild)
    _CreateIconFileFromHICON($hIcon, @ScriptDir & "\Test.ico")
    _WinAPI_DestroyIcon($hIcon)
    _GDIPlus_BitmapDispose($bild)
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    Func Resize($sFilename, $width = 64, $height = 64) ; code by UEZ 2011
    Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFilename)
    Local $iH = _GDIPlus_ImageGetHeight($hBitmap)
    Local $iW = _GDIPlus_ImageGetWidth($hBitmap)
    Local $hImage = _GDIPlus_BitmapCreateFromScan0($width, $height)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hImage)
    If $iW < $width And $iH < $height Then
    $w = $width / 2 - $iW / 2
    $h = $height / 2 - $iH / 2
    _GDIPlus_GraphicsDrawImageRect($hContext, $hBitmap, $width / 2 - $iW / 2, $height / 2 - $iH / 2, $iW, $iH)
    Else
    If $iW > $iH Then
    $f = $iW / $width
    Else
    $f = $iH / $height
    EndIf
    $w = $iW / $f
    $h = $iH / $f
    _GDIPlus_GraphicsDrawImageRect($hContext, $hBitmap, $width / 2 - $w / 2, $height / 2 - $h / 2, $w, $h)
    EndIf
    _GDIPlus_GraphicsDispose($hContext)
    _GDIPlus_BitmapDispose($hBitmap)
    Return SetError(0, 0, $hImage)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _CreateIconFileFromHICON($hIcon, $sOutIcon) ;code by smashly
    Local $aInfo, $sIco, $sBmp, $hCDC, $tBI, $tBits, $iSz, $sBD, $FO

    [/autoit] [autoit][/autoit] [autoit]

    ; Start of single Icon Header 3 x 2 bytes = 6 bytes: 0000 Reserved / 0100 Icon / 0100 Numer of icons, total length will be 22 bytes for a single icon when finished
    $sIco = "0x000001000100"

    [/autoit] [autoit][/autoit] [autoit]

    ; Start of the Bitmap data header 1 x 4bytes: length of the header will be 40 bytes when finished. Will be appended to the end of the icon header when finished
    $sBmp = "28000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; Get info about the HICON, this is mainly to get the pointers to the Color/Mask bitmaps data
    $aInfo = _WinAPI_GetIconInfo($hIcon)

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a memory Compatable DC
    $hCDC = _WinAPI_CreateCompatibleDC(0)

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a BITMAPINFO Struct to store the Bitmap Info, it needs to be inilialized by setting the struct size.
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))

    [/autoit] [autoit][/autoit] [autoit]

    ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the color bitmap data, we use it to write the headers
    _WinAPI_GetDIBits($hCDC, $aInfo[5], 0, 0, 0, DllStructGetPtr($tBI), 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; Now we have some the basic info to add to the Icon & Bitmap header so we'll add that to the headers.
    $sIco &= Hex(DllStructGetData($tBI, "Width"), 2) & Hex(DllStructGetData($tBI, "Height"), 2) & "00000100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4))
    $sBmp &= _RB(Hex(DllStructGetData($tBI, "Width"))) & _RB(Hex(DllStructGetData($tBI, "Height") * 2)) & "0100" & _RB(Hex(DllStructGetData($tBI, "BitCount"), 4)) & "00000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the size of the Bitmap data from the BITMAPINFO Struct, we'll use this in the headers further on.
    $iSz = DllStructGetData($tBI, "SizeImage")

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a struct to store the Bitmap data Bits of the first bitmap, reset the BITMAPINFO struct
    $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the color bitmap dib bits into the $tBits struct.
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[5], 'int', $iSz, 'ptr', DllStructGetPtr($tBits))

    [/autoit] [autoit][/autoit] [autoit]

    ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to Top to Bottom dib ;)
    ; ATM I'm only assuming that GetBitmapBits returns a Bottom to Top dib, maybe the bitmap bits you use could be Top Down already?.
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
    $sBD &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ;Clear the BITMAPINFO & $tBits Struct as we'll use the same variables again for the mask bitmap data
    $tBits = 0
    $tBI = 0

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a BITMAPINFO Struct to store the Bitmap Info again, it needs to be inilialized by setting the struct size.
    $tBI = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($tBI, "Size", DllStructGetSize($tBI))

    [/autoit] [autoit][/autoit] [autoit]

    ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the bitmask bitmap data
    _WinAPI_GetDIBits($hCDC, $aInfo[4], 0, 0, 0, DllStructGetPtr($tBI), 0)

    [/autoit] [autoit][/autoit] [autoit]

    ; We've finished with the Compatable DC, delete it.
    _WinAPI_DeleteDC($hCDC)

    [/autoit] [autoit][/autoit] [autoit]

    ; Add the size of the of the color + bitmask bitmap data as we need this for both the Icon & Bitmap header
    $iSz += DllStructGetData($tBI, "SizeImage")

    [/autoit] [autoit][/autoit] [autoit]

    ; combine the bitmap data size with the bitmap header, I'm padding the rest of the 40 byte bitmap header with 0's., that's the Bitmap header done
    $sBmp &= _RB(Hex($iSz)) & "00000000000000000000000000000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; Now add the size of the Bitmap data + bitmap header size and combine the icon header together with the bitmap header and color bitmap data
    $sIco &= _RB(Hex($iSz + 40)) & _RB(Hex("22")) & $sBmp & $sBD

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a struct to store the Bitmap dib Bits of the mask bitmap
    $tBits = DllStructCreate("byte[" & DllStructGetData($tBI, "SizeImage") & "]")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the mask bitmap dib bits into the $tBits struct.
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[4], 'int', DllStructGetData($tBI, "SizeImage"), 'ptr', DllStructGetPtr($tBits))

    [/autoit] [autoit][/autoit] [autoit]

    ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to a Top to Bottom dib and append the mask bitmap data to the icon
    For $i = DllStructGetData($tBI, "SizeImage") + 1 To 0 Step -(DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))
    $sIco &= StringTrimLeft(BinaryMid(DllStructGetData($tBits, 1), $i, (DllStructGetData($tBI, "SizeImage") / DllStructGetData($tBI, "Height"))), 2)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; Write the icon to a file.
    $FO = FileOpen($sOutIcon, 18)
    FileWrite($sOutIcon, Binary($sIco))
    FileClose($FO)

    [/autoit] [autoit][/autoit] [autoit]

    ; Clear the structs
    $tBits = 0
    $tBI = 0
    EndFunc ;==>_CreateIconFileFromHICON

    [/autoit] [autoit][/autoit] [autoit]

    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, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
    EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    Local $hIcon
    $hIcon = DllCall($ghGDIPDll, "int", "GdipCreateHICONFromBitmap", "hwnd", $hBitmap, "int*", 0)
    If @error Then Return SetError(@error, 0, -1)
    Return SetError($hIcon[0], 0, $hIcon[2])
    EndFunc ;==>_GDIPlus_BitmapCreateHICONFromBitmap

    [/autoit] [autoit][/autoit] [autoit]

    ; Reverse Byte String
    Func _RB($sByte)
    Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = ''
    For $i = UBound($aX) - 1 To 0 Step -1
    $sX &= $aX[$i]
    Next
    Return $sX
    EndFunc ;==>_RB

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Ich weiß, der Beitrag ist zwar veraltet,
    aber vielleicht kann das jemand anders auch mal gut gebrauchen.

    Ich hab mal das Script von smashly um die Möglichkeit erweitert,
    mehrere Icons in ein Icon einzufügen.
    _CreateIconFileFromHICON() erwartet jetzt ein Array von Icon Handeln.

    HICON.au3

    Spoiler anzeigen
    [autoit]

    #include-once
    #include <GDIPlus.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_Resize( ByRef $hBitmap, $width = 64, $height = 64) ; code by UEZ 2011
    Local $iH = _GDIPlus_ImageGetHeight($hBitmap)
    Local $iW = _GDIPlus_ImageGetWidth($hBitmap)
    Local $hImage = _GDIPlus_BitmapCreateFromScan0($width, $height)
    Local $hContext = _GDIPlus_ImageGetGraphicsContext($hImage)
    If $iW < $width And $iH < $height Then
    $w = $width / 2 - $iW / 2
    $h = $height / 2 - $iH / 2
    _GDIPlus_GraphicsDrawImageRect($hContext, $hBitmap, $width / 2 - $iW / 2, $height / 2 - $iH / 2, $iW, $iH)
    Else
    If $iW > $iH Then
    $f = $iW / $width
    Else
    $f = $iH / $height
    EndIf
    $w = $iW / $f
    $h = $iH / $f
    _GDIPlus_GraphicsDrawImageRect($hContext, $hBitmap, $width / 2 - $w / 2, $height / 2 - $h / 2, $w, $h)
    EndIf
    _GDIPlus_GraphicsDispose($hContext)
    Return SetError(0, 0, $hImage)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _CreateIconFileFromHICON( $aIcon, $sOutIcon ) ;code by smashly optemized by tromorow
    Local $sIco, $sBmp, $tBits, $iSz, $sBD, $FO, $i, $j
    Local $sHeader, $sData, $iDataSize
    Local $aInfo[10]

    [/autoit] [autoit][/autoit] [autoit]

    ; clear strings
    $sHeader = ""
    $sData = ""
    $iDataSize = 0 ; count of datas to get ico poss in mem

    [/autoit] [autoit][/autoit] [autoit]

    ; Start of single Icon Header 2 x 2 bytes = 6 bytes: 0000 Reserved / 0100 Icon / 0100 Numer of icons, total length will be 22 bytes for a single icon when finished
    $sIco = "0x00000100"&_PRIVATE_HICON_RB( Hex( UBound( $aIcon ), 4 ) )

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To UBound( $aIcon ) -1

    [/autoit] [autoit][/autoit] [autoit]

    $aInfo = _PRIVATE_HICON_GetIcoInfos( $aIcon[ $i ] )

    [/autoit] [autoit][/autoit] [autoit]

    ; Now we have some the basic info to add to the Icon & Bitmap header so we'll add that to the headers.
    $sHeader &= Hex( $aInfo[1], 2 ) & Hex( $aInfo[2], 2 ) & "00000100" & _PRIVATE_HICON_RB( Hex( $aInfo[3], 4 ) )
    ; now the size of both pics, size of ico + size of mask + bitmap header
    $sHeader &= _PRIVATE_HICON_RB( Hex( $aInfo[4] + $aInfo[9] + 40 ) )
    ; calculate beginning of pic and add to Header
    $sHeader &= _PRIVATE_HICON_RB( Hex( 6 + ( UBound( $aIcon ) * 16 ) + $iDataSize ) )
    ; add Datasize to counter
    $iDataSize += $aInfo[4] + $aInfo[9] + 40

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a struct to store the Bitmap data Bits of the first bitmap, reset the BITMAPINFO struct
    $tBits = 0
    $tBits = DllStructCreate("byte[" & $aInfo[4] & "]")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the color bitmap dib bits into the $tBits struct.
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[0], 'int', $aInfo[4], 'ptr', DllStructGetPtr($tBits))

    [/autoit] [autoit][/autoit] [autoit]

    ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to Top to Bottom dib ;)
    ; ATM I'm only assuming that GetBitmapBits returns a Bottom to Top dib, maybe the bitmap bits you use could be Top Down already?.
    $sBD = ""
    For $j = $aInfo[4] + 1 To 0 Step -( $aInfo[4] / $aInfo[2] )
    $sBD &= StringTrimLeft( BinaryMid( DllStructGetData( $tBits, 1 ), $j, ( $aInfo[4] / $aInfo[2] ) ), 2 )
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; Start of the Bitmap data header 1 x 4bytes: length of the header will be 40 bytes when finished. Will be appended to the end of the icon header when finished
    $sBmp = "28000000"
    $sBmp &= _PRIVATE_HICON_RB( Hex( $aInfo[1] ) ) & _PRIVATE_HICON_RB( Hex( $aInfo[2] * 2) ) & "0100" & _PRIVATE_HICON_RB( Hex( $aInfo[3], 4 ) ) & "00000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; combine the bitmap data size with the bitmap header, I'm padding the rest of the 40 byte bitmap header with 0's., that's the Bitmap header done
    $sBmp &= _PRIVATE_HICON_RB( Hex( $aInfo[4] + $aInfo[9] ) ) & "00000000000000000000000000000000"

    [/autoit] [autoit][/autoit] [autoit]

    ; Now add the size of the Bitmap data + bitmap header size and combine the icon header together with the bitmap header and color bitmap data
    $sData &= $sBmp & $sBD

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a struct to store the Bitmap dib Bits of the mask bitmap
    $tBits = 0
    $tBits = DllStructCreate("byte[" & $aInfo[9] & "]")

    [/autoit] [autoit][/autoit] [autoit]

    ; Get the mask bitmap dib bits into the $tBits struct.
    DllCall('gdi32.dll', 'int', 'GetBitmapBits', 'ptr', $aInfo[5], 'int', $aInfo[9], 'ptr', DllStructGetPtr($tBits))

    [/autoit] [autoit][/autoit] [autoit]

    ; Get GetBitmapBits returns Bottom to Top dib, so I turn it to a Top to Bottom dib and append the mask bitmap data to the icon
    For $j = $aInfo[9] + 1 To 0 Step -( $aInfo[9] / $aInfo[7] )
    $sData &= StringTrimLeft( BinaryMid( DllStructGetData( $tBits, 1 ), $j, ( $aInfo[9] / $aInfo[7] ) ), 2 )
    Next

    [/autoit] [autoit][/autoit] [autoit]

    Next

    [/autoit] [autoit][/autoit] [autoit]

    $sIco &= $sHeader & $sData

    [/autoit] [autoit][/autoit] [autoit]

    ; Write the icon to a file.
    $FO = FileOpen($sOutIcon, 18)
    FileWrite($sOutIcon, Binary($sIco))
    FileClose($FO)

    [/autoit] [autoit][/autoit] [autoit]

    ; Clear the structs
    $tBits = 0
    EndFunc ;==>_CreateIconFileFromHICON

    [/autoit] [autoit][/autoit] [autoit]

    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, "int*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    Return $aResult[6]
    EndFunc ;==>_GDIPlus_BitmapCreateFromScan0

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    Local $hIcon
    $hIcon = DllCall($ghGDIPDll, "int", "GdipCreateHICONFromBitmap", "hwnd", $hBitmap, "int*", 0)
    If @error Then Return SetError(@error, 0, -1)
    Return SetError($hIcon[0], 0, $hIcon[2])
    EndFunc ;==>_GDIPlus_BitmapCreateHICONFromBitmap

    [/autoit] [autoit][/autoit] [autoit]

    Func _GDIPlus_BitmapCreateBitmapFromHICON($hIcon)
    ; Prog@ndy
    Local $result = DllCall($ghGDIPDLL, "int", "GdipCreateBitmapFromHICON", "ptr", $hIcon, "ptr*",0)
    If @error Then Return SetError(1,0,0)
    Return SetError($result[0], 1, $result[2])
    EndFunc ;==>_GDIPlus_BitmapCreateBitmapFromHICON

    [/autoit] [autoit][/autoit] [autoit]

    ; Reverse Byte String
    Func _PRIVATE_HICON_RB($sByte)
    Local $aX = StringRegExp($sByte, "(.{2})", 3), $sX = ''
    For $i = UBound($aX) - 1 To 0 Step -1
    $sX &= $aX[$i]
    Next
    Return $sX
    EndFunc ;==>_PRIVATE_HICON_RB

    [/autoit] [autoit][/autoit] [autoit]

    ; get Ico info
    Func _PRIVATE_HICON_GetIcoInfos( $hIcon )
    Local $aInfo, $hCDC, $tBI
    Local $ret[10]

    [/autoit] [autoit][/autoit] [autoit]

    ; Get info about the HICON, this is mainly to get the pointers to the Color/Mask bitmaps data
    $aInfo = _WinAPI_GetIconInfo( $hIcon )

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a memory Compatable DC
    $hCDC = _WinAPI_CreateCompatibleDC( 0 )

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a BITMAPINFO Struct to store the Bitmap Info, it needs to be inilialized by setting the struct size.
    $tBI = DllStructCreate( $tagBITMAPINFO )
    DllStructSetData( $tBI, "Size", DllStructGetSize( $tBI ) )

    [/autoit] [autoit][/autoit] [autoit]

    ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the color bitmap data, we use it to write the headers
    _WinAPI_GetDIBits( $hCDC, $aInfo[5], 0, 0, 0, DllStructGetPtr( $tBI ), 0)

    [/autoit] [autoit][/autoit] [autoit]

    $ret[0] = $aInfo[5]
    $ret[1] = DllStructGetData( $tBI, "Width" )
    $ret[2] = DllStructGetData( $tBI, "Height" )
    $ret[3] = DllStructGetData( $tBI, "BitCount" )
    $ret[4] = DllStructGetData( $tBI, "SizeImage" )

    [/autoit] [autoit][/autoit] [autoit]

    ;Clear the BITMAPINFO & $tBits Struct as we'll use the same variables again for the mask bitmap data
    $tBI = 0

    [/autoit] [autoit][/autoit] [autoit]

    ; Create a BITMAPINFO Struct to store the Bitmap Info again, it needs to be inilialized by setting the struct size.
    $tBI = DllStructCreate( $tagBITMAPINFO )
    DllStructSetData( $tBI, "Size", DllStructGetSize( $tBI ) )

    [/autoit] [autoit][/autoit] [autoit]

    ; Pass a bitmap data pointer to the BITMAPINFO struct so we can recieve the details of the bitmask bitmap data
    _WinAPI_GetDIBits( $hCDC, $aInfo[4], 0, 0, 0, DllStructGetPtr( $tBI ), 0 )

    [/autoit] [autoit][/autoit] [autoit]

    ; We've finished with the Compatable DC, delete it.
    _WinAPI_DeleteDC( $hCDC )

    [/autoit] [autoit][/autoit] [autoit]

    $ret[5] = $aInfo[4]
    $ret[6] = DllStructGetData( $tBI, "Width" )
    $ret[7] = DllStructGetData( $tBI, "Height" )
    $ret[8] = DllStructGetData( $tBI, "BitCount" )
    $ret[9] = DllStructGetData( $tBI, "SizeImage" )

    [/autoit] [autoit][/autoit] [autoit]

    ; Clear the structs
    $tBI = 0
    $hCDC = 0

    [/autoit] [autoit][/autoit] [autoit]

    Return $ret
    EndFunc

    [/autoit]


    Beispiel.au3

    Spoiler anzeigen
    [autoit]


    #include "HICON.au3"

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()

    [/autoit] [autoit][/autoit] [autoit]

    $hBitmap1 = _GDIPlus_BitmapCreateFromFile( "test1.jpg" )
    $hBitmap2 = _GDIPlus_BitmapCreateFromFile( "test2.jpg" )

    [/autoit] [autoit][/autoit] [autoit]

    Dim $aIcon[2]
    $aIcon[0] = _GDIPlus_HICONCreateFromBitmap( $hBitmap1 )
    $aIcon[1] = _GDIPlus_HICONCreateFromBitmap( $hBitmap2 )

    [/autoit] [autoit][/autoit] [autoit]

    _CreateIconFileFromHICON( $aIcon, "test.ico" )

    [/autoit] [autoit][/autoit] [autoit]

    _WinAPI_DestroyIcon( $aIcon[0] )
    _WinAPI_DestroyIcon( $aIcon[1] )
    _GDIPlus_BitmapDispose( $hBitmap )
    _GDIPlus_Shutdown()

    [/autoit]