• Hey,
    Da ich mich die Tage mit Hex beschäftigt habe, wobei mir Sprenger sehr geholfen hat, wollte ich direkt mal was kleines Basteln.

    Das Programm lädt ein Bild, ließt immer ein Bestimmtest Feld aus (Rechteck), nimmt daraus die Durschnitsfarbe und malt an die Stelle ein Rechteck.

    Den Grad der Verpixlung kann man in Zeile 18 und 19 ändern. 1 verpixelt garnicht.
    Ich weiß nicht wozu man es gebrauchen könnte, aber vllt hilt es ja jmd?

    PS: Das Script zum Darstellen von Bildern mit Kreisen von Fresapore hat mich inspiriert und auf die Idee gebracht, vorher wollte ich nicht direkt verpixeln. Es können ähnlichkeiten im Code vorkommen, was daran liegt das ich mir das Script von Fresspore öfters durchgelesen hab, bis ich verstanden hab wie es geht :)

    NEU:
    - Auswahl eines Bereichs der verpixelt werden soll (Danke an RapIt)

    Genug geredet, hier ist der Code:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    #include <GDIP.au3>

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

    Opt("GUIOnEventMode", 1)

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

    _GDIPlus_Startup()

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

    Global $hImage_Save
    Global $sSavePath = @DesktopDir & "\Test.png"

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

    Global $bClick = False

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

    Global $sPath = FileOpenDialog("", @DesktopDir, "All (*.*)")
    If $sPath = "" Then Exit
    $hImage = _GDIPlus_ImageLoadFromFile($sPath)

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

    Global $iWidth = _GDIPlus_ImageGetWidth($hImage)
    Global $iHeight = _GDIPlus_ImageGetHeight($hImage)

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

    Global $RecSize_Width = 15
    Global $RecSize_Height = 15
    Global $Edited = False

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

    Global $Multiplikator_A = 1
    Global $Multiplikator_R = 1
    Global $Multiplikator_G = 1
    Global $Multiplikator_B = 1

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

    Global $PixelRec_X = 0
    Global $PixelRec_Y = 0
    Global $PixelRec_Width = $iWidth
    Global $PixelRec_Height = $iHeight

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

    $hWnd = GUICreate("Test RRGGBB Durschnitswert", $iWidth+30, $iHeight + 50)
    GUISetOnEvent(-3, "_Exit", $hWnd)
    $hButton = GUICtrlCreateButton("Umwandeln", 0, $iHeight, $iWidth, 30, 0x0001)
    GUICtrlSetOnEvent($hButton, "_Umwandeln")
    $hProgress = GUICtrlCreateProgress(0, $iHeight + 30, $iWidth, 20)
    $hSlider = GUICtrlCreateSlider ($iWidth, 0, 30, $iHeight, 0x0002)
    GUICtrlSetLimit ($hSlider, 50, 2)
    GUISetState()

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

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    While 1
    $RecSize_Width = GUICtrlRead ($hSlider)
    $RecSize_Height = $RecSize_Width
    ToolTip ("Stärke der Verpixelung: "&$RecSize_Height)
    If $Edited = False Then _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage, 0, 0, $iWidth, $iHeight)
    If $Edited Then _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage_Save, 0, 0, $iWidth, $iHeight)

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

    $aMouse = GUIGetCursorInfo($hWnd)
    If IsArray($aMouse) Then
    If $aMouse[2] = 1 And $bClick = False And $aMouse[0] < $iWidth And $aMouse[1] < $iHeight Then
    $bClick = True
    $PixelRec_X = $aMouse[0]
    $PixelRec_Y = $aMouse[1]
    ElseIf $aMouse[2] = 0 And $bClick Then
    $bClick = False
    $PixelRec_Width = $aMouse[0] - $PixelRec_X
    $PixelRec_Height = $aMouse[1] - $PixelRec_Y
    EndIf
    EndIf

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

    If $bClick = True Then
    _GDIPlus_GraphicsDrawRect($hBackbuffer, $PixelRec_X - 1, $PixelRec_Y - 1, $aMouse[0] - $PixelRec_X + 1, $aMouse[1] - $PixelRec_Y + 1)
    ElseIf $bClick = False Then
    _GDIPlus_GraphicsDrawRect($hBackbuffer, $PixelRec_X - 1, $PixelRec_Y - 1, $PixelRec_Width + 1, $PixelRec_Height + 1)
    EndIf

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

    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight)
    WEnd

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

    Func _Umwandeln()
    _GDIPlus_GraphicsDrawImageRect($hBackbuffer, $hImage, 0, 0, $iWidth, $iHeight)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight)

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

    $Verarbeitet = 0
    $Pixelanzahl = $PixelRec_Width / $RecSize_Width
    For $i = $PixelRec_X / $RecSize_Width To $PixelRec_X / $RecSize_Width + ($PixelRec_Width / $RecSize_Width) - 1
    For $j = $PixelRec_Y / $RecSize_Height To $PixelRec_Y / $RecSize_Height + ($PixelRec_Height / $RecSize_Height) - 1
    $aColors = _GetColorOfRec($i * $RecSize_Width, $j * $RecSize_Height, $RecSize_Width, $RecSize_Height)
    $Hex = "0x" & $aColors[3] & $aColors[0] & $aColors[1] & $aColors[2]
    ;~ MsgBox(0, "", $Hex)
    $hBrush = _GDIPlus_BrushCreateSolid($Hex)
    _GDIPlus_GraphicsFillRect($hBackbuffer, $i * $RecSize_Width, $j * $RecSize_Height, $RecSize_Width, $RecSize_Height, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    Next
    $Verarbeitet += 1
    GUICtrlSetData($hProgress, $Verarbeitet * 100 / $Pixelanzahl)
    ToolTip(100 / $Pixelanzahl * $Verarbeitet & "/100")
    Next
    $Edited = True
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight)
    _GDIPlus_ImageSaveToFile($hBitmap, $sSavePath)
    _GDIPlus_ImageDispose($hImage)
    Global $hImage_Save = _GDIPlus_ImageLoadFromFile($sSavePath)

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

    EndFunc ;==>_Umwandeln

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

    Func _GetColorOfRec($iX, $iY, $iW, $iH)
    Local $r = 0, $g = 0, $b = 0, $a = 0
    For $i = $iX To $iX + $iW - 1
    For $j = $iY To $iY + $iH - 1
    $sColor = Hex(_GDIPlus_BitmapGetPixel($hBitmap, $i, $j))
    $a += Dec(StringLeft($sColor, 2)) * $Multiplikator_A
    $sColorWithoutAlpha = StringTrimLeft($sColor, 2)
    $r += Dec(StringLeft($sColorWithoutAlpha, 2)) * $Multiplikator_R
    $g += Dec(StringMid($sColorWithoutAlpha, 3, 2)) * $Multiplikator_G
    $b += Dec(StringRight($sColorWithoutAlpha, 2)) * $Multiplikator_B
    Next
    Next
    Dim $aColors[4]
    $aColors[0] = Hex($r / ($iW * $iH), 2)
    $aColors[1] = Hex($g / ($iW * $iH), 2)
    $aColors[2] = Hex($b / ($iW * $iH), 2)
    $aColors[3] = Hex($a / ($iW * $iH), 2)
    Return $aColors
    EndFunc ;==>_GetColorOfRec

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

    Func _Exit()
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ImageDispose($hImage_Save)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)

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

    _GDIPlus_Shutdown()

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

    Exit
    EndFunc ;==>_Exit

    [/autoit]

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake

    3 Mal editiert, zuletzt von BadBunny (20. August 2011 um 21:33)

  • Liegt daran weil er immer nur die ganzen Pixelblöcke malt, also wenn die Fläche die verpixelt werden soll 10x10 ist und die Pixelfelder 6x6, dann verpixelt er die letzten 4x4 Pixel nicht.

    mfg BB

    "IF YOU'RE GOING TO KILL IT
    OPEN SOURCE IT!"

    by Phillip Torrone

    Zitat von Shoutbox

    [Heute, 11:16] Andy: ....böseböseböseböse....da erinnere ich mich daran, dass man den Puschelschwanz eines KaRnickels auch "Blume" nennt....ob da eins zum anderen passt? :rofl: :rofl: :rofl: :rofl:

    https://autoit.de/index.php?page…leIt#post251138

    Neon Snake