Icons glätten?

  • Hi,
    gibt es eine Möglichkeit Icons zu glätten?
    Oder sonst wie die Qualität zu verbessern?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

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

    GUICreate("Meine GUI Icons", 700, 300)

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

    $icon = "C:\Windows\system32\mobsync.exe"

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

    GUICtrlCreateIcon($icon, 0, 20, 20, 12, 12)
    GUICtrlCreateIcon($icon, 0, 100, 20, 24, 24)
    GUICtrlCreateIcon($icon, 0, 200, 20)
    GUICtrlCreateIcon($icon, 0, 300, 20, 256, 256)
    GUISetState()

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

    While 1
    Local $msg = GUIGetMsg()

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

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd

    [/autoit]
  • Die Icons sind in 4, 8 und 32 Bit und in einer Auflösung von 16x16, 32x32, 48x48 und 256x256 abgespeichert. D.h. du solltest je nach Bedarf das entsprechende Icon dir heraussuchen.

    Einen Icon in 32x32 auf 256x256 zu skalieren, macht hier keinen Sinn.

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>

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

    GUICreate("Meine GUI Icons", 700, 300)

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

    $icon = "C:\Windows\system32\mobsync.exe"

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

    GUICtrlCreateIcon($icon, 1, 20, 20, 16, 16)
    GUICtrlCreateIcon($icon, 1, 100, 20, 32, 32)
    GUICtrlCreateIcon($icon, 1, 200, 20, 48, 48)
    GUICtrlCreateIcon($icon, 1, 300, 20, 256, 256)
    GUISetState()

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

    While 1
    Local $msg = GUIGetMsg()

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

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd

    [/autoit]

    Notfalls muss du das Icon mit GDI+ / WinAPI extrahieren und skalieren.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (11. April 2013 um 21:04)

  • meistertogo
    Dies ist mir schon klar, jedoch sind die Icons in Dateien die nicht von mir sind

    UEZ
    Ist dann die Qualität besser?
    Kann du mir auf die Sprünge helfen, welche Befehle da gebraucht werden.
    Mit WinAPI und GDI+ tue ich mich immer schwer.

    EDIT: Hab nun doch noch was gefunden.
    Momentan benötige die Qualität bei dem Icon 24x24.
    Dieses ist mit GDI+ leider auch nicht besser :wacko:

    Spoiler anzeigen
    [autoit]

    #Region ;************ Includes ************
    #Include <WinAPI.au3>
    #include <GUIConstantsEx.au3>
    #EndRegion ;************ Includes ************

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

    $hGui = GUICreate("Meine GUI Icons", 700, 600)

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

    $icon = "C:\Windows\system32\mobsync.exe"

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

    GUICtrlCreateIcon($icon, 1, 20, 20, 12, 12)
    GUICtrlCreateIcon($icon, 1, 100, 20, 24, 24)
    GUICtrlCreateIcon($icon, 1, 200, 20, 64, 64)
    GUICtrlCreateIcon($icon, 1, 300, 20, 256, 256)

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

    $hIcon = _WinAPI_PrivateExtractIcon($icon, 0, 256, 256)

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

    GUISetState()

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

    $hDC = _WinAPI_GetDC($hGui)

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

    _WinAPI_DrawIconEx($hDC, 20, 40, $hIcon, 12, 12)
    _WinAPI_DrawIconEx($hDC, 100, 60, $hIcon, 24, 24)
    _WinAPI_DrawIconEx($hDC, 200, 100, $hIcon, 64, 64)
    _WinAPI_DrawIconEx($hDC, 300, 280, $hIcon, 256, 256)

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

    While 1
    Local $msg = GUIGetMsg()

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

    If $msg = $GUI_EVENT_CLOSE Then
    _WinAPI_DestroyIcon($hIcon)
    ExitLoop
    EndIf
    WEnd

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

    Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)

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

    Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd')
    Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0)

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

    If (@error) Or ($Ret[0] = 0) Then
    Return SetError(1, 0, 0)
    EndIf
    $hIcon = DllStructGetData($tIcon, 1)
    If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then
    Return SetError(1, 0, 0)
    EndIf
    Return $hIcon
    EndFunc ;==>_WinAPI_PrivateExtractIcon

    [/autoit]
  • Hier ein Beispiel:

    Spoiler anzeigen
    [autoit]


    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    Opt("MustDeclareVars", 1)

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

    _GDIPlus_Startup()
    Global Const $STM_SETIMAGE = 0x0172

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

    Global $hGUI, $Msg, $Button, $Icon, $hIcon, $iPic, $hPic, $hGraphics, $Index = 0, $iBGColor = 0xF0F0F0
    Global $hIcon300x300 = _WinAPI_ShellExtractIcon("C:\Windows\system32\mobsync.exe", $Index, 300, 300)
    Global $hHBitmap256x256 = _WinAPI_GetFileIcon("C:\Windows\system32\mobsync.exe", $Index, 256, 256, $iBGColor)
    Global $hBitmapIcon256x256 = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap256x256)
    Global $hBitmapIcon300x300 = _GDIPlus_BitmapCreateFromScan0(300, 300)
    Global $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmapIcon300x300)
    _GDIPlus_GraphicsSetInterpolationMode($hContext, 7)
    _GDIPlus_GraphicsDrawImageRect($hContext, $hBitmapIcon256x256, 0, 0, 300, 300)
    _GDIPlus_GraphicsDispose($hContext)

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

    $hGUI = GUICreate("MyGUI", 610, 300)
    GUISetBkColor($iBGColor)
    $Icon = GUICtrlCreateIcon("", 0, 0, 0, 300, 300)
    $hIcon = GUICtrlGetHandle(-1)
    $iPic = GUICtrlCreatePic("", 310,0, 300, 300)
    $hPic = GUICtrlGetHandle(-1)
    GUISetState()
    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hPic)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmapIcon300x300, 0, 0, 300, 300)
    _WinAPI_DestroyIcon(_SendMessage($hIcon, $STM_SETIMAGE, 1, $hIcon300x300))

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

    While 1
    $Msg = GUIGetMsg()
    Switch $Msg
    Case -3
    _GDIPlus_BitmapDispose($hBitmapIcon256x256)
    _GDIPlus_BitmapDispose($hBitmapIcon300x300)
    _WinAPI_DestroyIcon($hIcon300x300)
    _WinAPI_DeleteObject($hHBitmap256x256)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    ExitLoop
    EndSwitch
    WEnd

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

    Func _WinAPI_GetFileIcon($sFile, $iIndex = 0, $iW = 18, $iH = 18, $iColor = -1)
    Local $aRet, $hIcon, $hHBitmap
    Local $hDC, $hBackDC, $hBackSv

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

    $aRet = DllCall("shell32.dll", "int", "SHExtractIconsW", "wstr", $sFile, "int", $iIndex, "int", $iW, "int", $iH, "ptr*", 0, "ptr*", 0, "int", 1, "int", 0)
    If @error Then Return SetError(6, @extended, 0)
    $hIcon = $aRet[5]

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

    $hDC = _WinAPI_GetDC(0)
    $hBackDC = _WinAPI_CreateCompatibleDC($hDC)
    If $iColor = -1 Then $iColor = _WinAPI_GetSysColor($COLOR_MENU)
    $hHBitmap = _WinAPI_CreateSolidBitmap(0, $iColor, $iW, $iH)
    $hBackSv = _WinAPI_SelectObject($hBackDC, $hHBitmap)
    _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, $iW, $iH)
    _WinAPI_DestroyIcon($hIcon)

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

    _WinAPI_SelectObject($hBackDC, $hBackSv)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteDC($hBackDC)
    Return $hHBitmap
    EndFunc ;==>_GUICtrlMenu_CreateBitmap

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _WinAPI_ShellExtractIcon
    ; Description....: Extracts the icon with the specified dimension from the specified file.
    ; Syntax.........: _WinAPI_ShellExtractIcon ( $sIcon, $iIndex, $iWidth, $iHeight )
    ; Parameters.....: $sIcon - Path and name of the file from which the icon are to be extracted.
    ; $iIndex - The zero-based index of the icon to extract. If this value is a negative number, the function extracts
    ; the icon whose resource identifier is equal to the absolute value of $iIndex.
    ; $iWidth - Horizontal icon size wanted.
    ; $iHeight - Vertical icon size wanted.
    ; Return values..: Success - Handle to the extracted icon.
    ; Failure - 0 and sets the @error flag to non-zero.
    ; Author.........: Yashied
    ; Modified.......:
    ; Remarks........: If the icon with the specified dimension is not found in the file, it will choose the nearest appropriate icon
    ; and change to the specified dimension.
    ;
    ; When you are finished using the icon, destroy it using the _WinAPI_DestroyIcon() function.
    ; Related........:
    ; Link...........: @@MsdnLink@@ SHExtractIcons
    ; Example........: Yes
    ; ===============================================================================================================================
    Func _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight)
    Local $Ret = DllCall("shell32.dll", "int", "SHExtractIconsW", "wstr", $sIcon, "int", $iIndex, "int", $iWidth, "int", $iHeight, "ptr*", 0, "ptr*", 0, "int", 1, "int", 0)
    If (@error) Or (Not $Ret[0]) Or (Not $Ret[5]) Then
    Return SetError(1, 0, 0)
    EndIf
    Return $Ret[5]
    EndFunc ;==>_WinAPI_ShellExtractIcon

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

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_BitmapCreateFromScan0
    ; Description ...: Creates a Bitmap object based on an array of bytes along with size and format information
    ; Syntax.........: _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight[, $iStride = 0[, $iPixelFormat = 0x0026200A[, $pScan0 = 0]]])
    ; Parameters ....: $iWidth - The bitmap width, in pixels
    ; $iHeight - The bitmap height, in pixels
    ; $iStride - Integer that specifies the byte offset between the beginning of one scan line and the next. This
    ; +is usually (but not necessarily) the number of bytes in the pixel format (for example, 2 for 16 bits per pixel)
    ; +multiplied by the width of the bitmap. The value passed to this parameter must be a multiple of four
    ; $iPixelFormat - Specifies the format of the pixel data. Can be one of the following:
    ; |$GDIP_PXF01INDEXED - 1 bpp, indexed
    ; |$GDIP_PXF04INDEXED - 4 bpp, indexed
    ; |$GDIP_PXF08INDEXED - 8 bpp, indexed
    ; |$GDIP_PXF16GRAYSCALE - 16 bpp, grayscale
    ; |$GDIP_PXF16RGB555 - 16 bpp; 5 bits for each RGB
    ; |$GDIP_PXF16RGB565 - 16 bpp; 5 bits red, 6 bits green, and 5 bits blue
    ; |$GDIP_PXF16ARGB1555 - 16 bpp; 1 bit for alpha and 5 bits for each RGB component
    ; |$GDIP_PXF24RGB - 24 bpp; 8 bits for each RGB
    ; |$GDIP_PXF32RGB - 32 bpp; 8 bits for each RGB. No alpha.
    ; |$GDIP_PXF32ARGB - 32 bpp; 8 bits for each RGB and alpha
    ; |$GDIP_PXF32PARGB - 32 bpp; 8 bits for each RGB and alpha, pre-mulitiplied
    ; $pScan0 - Pointer to an array of bytes that contains the pixel data. The caller is responsible for
    ; +allocating and freeing the block of memory pointed to by this parameter.
    ; Return values .: Success - Returns a handle to a new Bitmap object
    ; Failure - 0 and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: After you are done with the object, call _GDIPlus_ImageDispose to release the object resources
    ; Related .......: _GDIPlus_ImageDispose
    ; Link ..........; @@MsdnLink@@ GdipCreateBitmapFromScan0
    ; Example .......; Yes
    ; ===============================================================================================================================
    Func _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight, $iStride = 0, $iPixelFormat = $GDIP_PXF32RGB, $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]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_GraphicsSetInterpolationMode
    ; Description ...: Sets the interpolation mode of a Graphics object
    ; Syntax.........: _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
    ; Parameters ....: $hGraphics - Pointer to a Graphics object
    ; $iInterpolationMode - Interpolation mode:
    ; |0 - Default interpolation mode
    ; |1 - Low-quality mode
    ; |2 - High-quality mode
    ; |3 - Bilinear interpolation. No prefiltering is done
    ; |4 - Bicubic interpolation. No prefiltering is done
    ; |5 - Nearest-neighbor interpolation
    ; |6 - High-quality, bilinear interpolation. Prefiltering is performed to ensure high-quality shrinking
    ; |7 - High-quality, bicubic interpolation. Prefiltering is performed to ensure high-quality shrinking
    ; Return values .: Success - True
    ; Failure - False and either:
    ; |@error and @extended are set if DllCall failed
    ; |$GDIP_STATUS contains a non zero value specifying the error code
    ; Remarks .......: The interpolation mode determines the algorithm that is used when images are scaled or rotated
    ; Related .......: _GDIPlus_GraphicsGetInterpolationMode
    ; Link ..........; @@MsdnLink@@ GdipSetInterpolationMode
    ; Example .......; No
    ; ===============================================================================================================================
    Func _GDIPlus_GraphicsSetInterpolationMode($hGraphics, $iInterpolationMode)
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hGraphics, "int", $iInterpolationMode)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0] = 0
    EndFunc ;==>_GDIPlus_GraphicsSetInterpolationMode

    [/autoit]

    Kannst das Beispiel entsprechend ändern und die Bitmap in 24x24 erstellen und abspeichern. Die Quali sollte besser sein.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Wow :!:
    Wiedermal genial.

    Ich habe noch das anzeigen über GuiCtrlCreateIcon ergänzt.
    Sehe ich es richtig, dass ich die beste Qualität über "dein" GuiCtrlCreateIcon erreiche?
    Was hätte GuiCtrlCreatePic für einen Vorteil? Hier sehe ich nur den Nachteil, dass das Icon verschwindet, wenn ich die GUI minimiere.

    Habe ich die Werte richtig geändert, dass es mir 24x24 anzeigt?

  • GuiCtrlCreatePic() dient nur zum Anzeigen des GDI+ Bildes, um das Resultat zu vergleichen. Besser wäre es, das GDI+ Bild an den Control zu schicken, dann würde das Bild auch nicht gelöscht.

    Suche dir das Beste aus. ;)


    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯