Bild in Icon umwandeln?

  • HICON ist einfach. Das in eine Datei speichern ist aufwendig. Anfang:

    Spoiler anzeigen
    [autoit]

    #include <gdiplus.au3>
    #include <windowsconstants.au3>
    #include <constants.au3>
    Global Const $DIB_RGB_COLORS = 0
    Func _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    ; Prog@ndy
    Local $result = DllCall($ghGDIPDLL, "int", "GdipCreateHICONFromBitmap", "ptr", $hBitmap, "ptr*", 0)
    If @error Then Return SetError(1,1,0)
    Return SetError($result[0],0,$result[2])
    EndFunc

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

    Global Const $tagBITMAP = "LONG bmType; LONG bmWidth; LONG bmHeight; LONG bmWidthBytes; ushort bmPlanes; ushort bmBitsPixel; ptr bmBits; "
    Global Const $tagBITMAPINFOHEADER = "DWORD biSize; LONG biWidth; LONG biHeight; ushort biPlanes; ushort biBitCount DWORD biCompression; DWORD biSizeImage; LONG biXPelsPerMeter; LONG biYPelsPerMeter; DWORD biClrUsed; DWORD biClrImportant;"

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

    Global Const $tagICONDIRHEADER = "ushort idReserved; ushort idType; ushort idCount;"
    Global Const $tagICONDIRENTRY = _
    "BYTE bWidth; " & _ ;// Width, in pixels, of the image
    "BYTE bHeight; " & _ ;// Height, in pixels, of the image
    "BYTE bColorCount; " & _ ;// Number of colors in image (0 if >=8bpp)
    "BYTE bReserved; " & _ ;// Reserved ( must be 0)
    "ushort wPlanes; " & _ ;// Color Planes
    "WORD wBitCount; " & _ ;// Bits per pixel
    "DWORD dwBytesInRes;" & _ ;// How many bytes in this resource?
    "DWORD dwImageOffset;" ;// Where in the file is this image?

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

    _GDIPlus_Startup()

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

    $hBitmap = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\eigene bilder\au3.png")

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

    $hIcon = _GDIPlus_BitmapCreateHICONFromBitmap($hBitmap)
    $aInfo = _WinAPI_GetIconInfo($hIcon)

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

    $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    $hDC = _GDIPlus_GraphicsGetDC($hGraphics)

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

    $bmpinfo = DllStructCreate($tagBITMAPINFO)
    DllStructSetData($bmpinfo, 1, DllStructGetSize($bmpinfo)-4)

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

    $info = DllStructCreate($tagBITMAP)

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

    _WinAPI_GetObject($aInfo[4], DllStructGetSize($info), DllStructGetPtr($info) )

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

    _WinAPI_GetDIBits($hDC, $aInfo[4], 0, DllStructGetData($info, 3), 0, DllStructGetPtr($bmpinfo), $DIB_RGB_COLORS)
    MsgBox(0, '', DllStructGetData($bmpinfo, 3))

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

    _GDIPlus_GraphicsReleaseDC($hGraphics, $hDC)
    _GDIPlus_GraphicsDispose($hGraphics)
    _WinAPI_DestroyIcon($hIcon)
    _GDIPlus_ImageDispose($hBitmap)
    _GDIPlus_Shutdown()

    [/autoit]


    da fehlt aber noch einiges.
    http://msdn.microsoft.com/en-us/library/ms997538.aspx
    http://en.wikipedia.org/wiki/ICO_(icon…#File_structure
    http://msdn.microsoft.com/en-us/library/ms648052(VS.85).aspx
    ...

  • thx...wie hilft mir dieser hicon jetzt weiter :S ?

    und noch was der icon muss auch nicht aus mehreren größen bestehn eine größe reicht zb ( 48x48 )

    mfg team2way

    Einmal editiert, zuletzt von team2way (13. März 2009 um 09:57)

  • Hi

    Noch nichts... ;)
    Du mußt noch warten, bis Progady den Code fertig hat!
    Und das ist, wie er selbst schon gesagt hat, ziemlich aufwändig...

    Alternativ könntest du FreeImage.dll benutzen, die ist allerdings 2mb groß.

    [autoit]

    $BMPFile = @ScriptDir & "\Test.bmp"

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

    $FIF_BMP = 0
    $FIF_ICO = 1
    $FILTER_LANCZOS3 = 5

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

    $FIDll = DllOpen(@ScriptDir & "\FreeImage.dll")

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

    $FIPic = DllCall($FIDll, "dword", "_FreeImage_Load@12", "dword", $FIF_BMP, "str", $BMPFile, "int", 0)
    $FIPic_1 = DllCall($FIDll, "dword", "_FreeImage_Rescale@16", "dword", $FIPic[0], "int", 48, "int", 48, "dword", $FILTER_LANCZOS3)
    DllCall($FIDll, "int", "_FreeImage_Save@16", "int", $FIF_ICO, "dword", $FIPic_1[0], "str", StringTrimRight($BMPFile, 3) & "ico", "int", 0)

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

    $Ret=DllCall($FIDll, "int", "_FreeImage_Unload@4", "dword", $FIPic_1[0])
    $Ret=DllCall($FIDll, "int", "_FreeImage_Unload@4", "dword", $FIPic[0])

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

    DllClose($FIDll)

    [/autoit]
  • kann ich die dann für mein programm vorerst mal nutzen wenn ich es als freeware zum download anbiete?

    Einmal editiert, zuletzt von team2way (13. März 2009 um 10:18)

  • hab dein script gerade mal mit der freeimage.dll getestet...

    bei mir kommt da ein fehler in zeile 11

    Error: Subscript used with non-Array variable???

  • Wurde die Dll richtig geladen? $FIDLL = 1 ?
    Wurde das Bild richtig geladen? $FIPic[0] > 0 ?

    Falls du ein anderes Format als Bmp laden willst, mußt du die $FIF_BMP in Zeile 9 ersetzen.
    zb.: JPG hat den Wert 2, TIFF den Wert 18...

    Lade dir auch den Freeimage Source herunter, da findest du alle weiteren Constanten...

  • eukalyptus ich hab nur dein programm getestet - mit deinem bild "Test.bmp"

    in dem ordner befand sich die das au3 script das bild und die FreeImage.dll...also ka wo da jetzt der fehler liegt.

    hier noch mal der fehlerbericht:

    Code
    Line 11 
    DllCall($FIDll, "int", "_FreeImage_Save@16", "int", $FIF_ICO, "dword", $FIPic_1[0], "str", StringTrimRight($BMPFile, 3) & "ico", "int", 0)
    $Ret=DllCall($FIDll, "int", "_FreeImage_Unload@4", "dword", $FIPic_1^ERROR
    
    
    Error: Subscript used with non-Array variable


    denk mal da is irwas mit dem scipt nich in ordnung

    mfg team2way