GDI+ Farbübergänge

  • so etwas ähnliches....

    Bild auswählen und die Farben werden mit denen einer selbst erstellten Palette (Farbverlauf) ersetzt

    Spoiler anzeigen
    [autoit]

    #include <WinAPI.au3>

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

    Opt("MouseCoordMode", 2)
    Opt("PixelCoordMode", 2)

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

    $user32 = DllOpen("user32.dll")
    $gdi32 = DllOpen("gdi32.dll")

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

    Dim $red[2], $green[2], $blue[2], $bar[256]
    $palette = "0x"

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

    ;start- and endcolor in BGR
    startcolor(0, 0, 0) ;[1] BGR black
    endcolor(0, 0, 255) ;[0] red
    For $i = 0 To 64 ;Gradient from black to red, 64 steps
    $xx = $i / 64
    $r = Int($red[0] - ($red[0] - $red[1]) * $xx) * 256 * 256
    $g = Int($green[0] - ($green[0] - $green[1]) * $xx) * 256
    $b = Int($blue[0] - ($blue[0] - $blue[1]) * $xx)
    $bar[$i] = ($r + $g + $b)
    $palette &= Hex($bar[$i], 8)
    Next

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

    startcolor(0, 0, 255) ;[1] red
    endcolor(0, 255, 255) ;[0] yellow

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

    For $i = 64 To 128
    $xx = ($i - 64) / 64
    $r = Int($red[0] - ($red[0] - $red[1]) * $xx) * 256 * 256
    $g = Int($green[0] - ($green[0] - $green[1]) * $xx) * 256
    $b = Int($blue[0] - ($blue[0] - $blue[1]) * $xx)
    $bar[$i] = ($r + $g + $b)
    $palette &= Hex($bar[$i], 8)
    Next
    startcolor(0, 255, 255) ;[1] yellow
    endcolor(255, 255, 255) ;[0] white

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

    For $i = 128 To 192
    $xx = ($i - 128) / 64
    $r = Int($red[0] - ($red[0] - $red[1]) * $xx) * 256 * 256
    $g = Int($green[0] - ($green[0] - $green[1]) * $xx) * 256
    $b = Int($blue[0] - ($blue[0] - $blue[1]) * $xx)
    $bar[$i] = ($r + $g + $b)
    $palette &= Hex($bar[$i], 8)
    Next

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

    startcolor(255, 255, 255) ;[1] white
    endcolor(0, 0, 0) ;[0] black
    For $i = 192 To 255
    $xx = ($i - 192) / 64
    $r = Int($red[0] - ($red[0] - $red[1]) * $xx) * 256 * 256
    $g = Int($green[0] - ($green[0] - $green[1]) * $xx) * 256
    $b = Int($blue[0] - ($blue[0] - $blue[1]) * $xx)
    $bar[$i] = ($r + $g + $b)
    $palette &= Hex($bar[$i], 8)
    Next

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

    $struct = DllStructCreate("dword[256]") ;32Bit 256 mal

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

    $palette = "0x"
    Dim $z[256]
    For $i = 0 To 223
    $z[$i + 32] = $bar[$i]
    $palette &= Hex($bar[$i], 8)
    Next
    For $i = 224 To 255
    $z[$i - 223] = $bar[$i]
    $palette &= Hex($bar[$i], 8)
    Next
    $bar = $z

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

    ;~ ;_arraydisplay($bar)

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

    $hgui = GUICreate("Palette", 800, 500, -1, -1)
    $pic = GUICtrlCreatePic(FileOpenDialog("Datei laden", @ScriptDir, "(*.jpg;*.bmp;*.png)", 16), 0, 0, 400, 400)
    $hdc = _WinAPI_GetDC(WinGetHandle($hgui))

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

    GUISetState()
    ;display palette
    for $y=0 to 50
    for $x=0 to 255
    pix($hdc,$x,$y+420,$bar[$x]);col in BGR
    Next
    next
    ;~ ;_arraydisplay($bar)
    ;display transformed picture

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

    For $x = 0 To 400
    For $y = 0 To 400
    $col = PixelGetColor($x, $y)
    $rest = Mod($col, 255) ;replace the color of the pixel in de source with a color of the palette
    pix($hdc, $x + 400, $y, $bar[$rest]);col in BGR
    Next
    Next

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

    Do
    ToolTip(Hex(PixelGetColor(MouseGetPos(0), MouseGetPos(1), $hgui))) ;anzeige der Pixelcolor unter dem Mauszeiger
    Until GUIGetMsg() = -3

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

    Func pix($dc, $x, $y, $color) ;pixel mit color an koordinaten setzen
    DllCall($gdi32, "long", "SetPixel", "long", $dc, "long", $x, "long", $y, "long", $color)
    EndFunc ;==>pix

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

    Func endcolor($r, $g, $b)
    $red[1] = $r
    $green[1] = $g
    $blue[1] = $b
    EndFunc ;==>endcolor

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

    Func startcolor($r, $g, $b)
    $red[0] = $r
    $green[0] = $g
    $blue[0] = $b
    EndFunc ;==>startcolor

    [/autoit]

    ciao
    Andy


    "Schlechtes Benehmen halten die Leute doch nur deswegen für eine Art Vorrecht, weil keiner ihnen aufs Maul haut." Klaus Kinski
    "Hint: Write comments after each line. So you can (better) see what your program does and what it not does. And we can see what you're thinking what your program does and we can point to the missunderstandings." A-Jay

    Wie man Fragen richtig stellt... Tutorial: Wie man Script-Fehler findet und beseitigt...X-Y-Problem

    2 Mal editiert, zuletzt von Andy (28. September 2013 um 23:28)

  • Schade, jetzt hat ich auch extra noch was gemacht, war wohl zu langsam :D

    Naja fürs nächste mal:

    Spoiler anzeigen
    [autoit]

    #include <Color.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>
    Opt("GUIOnEventMode", 1)
    OnAutoItExitRegister("__GDIPlus_Shutdown")
    _GDIPlus_Startup()

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

    Global $iWidth = 400, $iHeight = 400

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

    $hGUI = GUICreate("", $iWidth, $iHeight)
    GUISetOnEvent(-3, "OnEvent_Eventhandler")
    GUIRegisterMsg($WM_PAINT, "WM_PAINT")

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

    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)

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

    GUISetState()
    While 1 * Sleep(10)
    WM_PAINT()
    WEnd

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

    Func OnEvent_Eventhandler()
    Exit
    EndFunc ;==>OnEvent_Eventhandler

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

    Func WM_PAINT()
    _GDIPlus_GraphicsClear($hBackbuffer, 0xFF000000 + _NewColor())
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_PAINT

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

    Func __GDIPlus_Shutdown()
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    EndFunc ;==>__GDIPlus_Shutdown

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

    Func _NewColor()
    Local $iStep = 5
    Local Static $aRGB[3] = [255, 45, 45], $iIndex = 0, $fDown = False
    If $fDown Then
    $aRGB[$iIndex] -= $iStep
    If $aRGB[$iIndex] <= 45 Then
    $aRGB[$iIndex] = 45
    $iIndex = Mod($iIndex + 1, 3)
    $fDown = False
    EndIf
    Else
    Local $iHoch = Mod($iIndex + 1, 3)
    $aRGB[$iHoch] += $iStep
    If $aRGB[$iHoch] >= 255 Then
    $aRGB[$iHoch] = 255
    $fDown = True
    EndIf
    EndIf
    ConsoleWrite($aRGB[0] & @TAB & $aRGB[1] & @TAB & $aRGB[2] & @TAB & @CRLF)
    Return _ColorSetRGB($aRGB)
    EndFunc ;==>_NewColor

    [/autoit]

    PS: Kann unnützes Zeug mit drin sein. ich hab ein GDI - Abbrev

    //EDIT: Scheine, das Thema eh verfehlt zu haben :D