Hat jemand eine Idee oder ein Beispiel wie sich fließende Farbübergänge mit GDI+ realisieren ließen?
GDI+ Farbübergänge
-
- [ offen ]
-
name22 -
13. März 2010 um 22:05 -
Geschlossen -
Erledigt
-
-
Meinst du so was: GDI+ Farbverlauf erstellen?
Gruß,
UEZ -
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)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Opt("PixelCoordMode", 2)$user32 = DllOpen("user32.dll")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$gdi32 = DllOpen("gdi32.dll")Dim $red[2], $green[2], $blue[2], $bar[256]
[/autoit] [autoit][/autoit] [autoit]
$palette = "0x";start- and endcolor in BGR
[/autoit] [autoit][/autoit] [autoit]
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],
Nextstartcolor(0, 0, 255) ;[1] red
[/autoit] [autoit][/autoit] [autoit]
endcolor(0, 255, 255) ;[0] yellowFor $i = 64 To 128
[/autoit] [autoit][/autoit] [autoit]
$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],
Next
startcolor(0, 255, 255) ;[1] yellow
endcolor(255, 255, 255) ;[0] whiteFor $i = 128 To 192
[/autoit] [autoit][/autoit] [autoit]
$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],
Nextstartcolor(255, 255, 255) ;[1] white
[/autoit] [autoit][/autoit] [autoit]
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],
Next$struct = DllStructCreate("dword[256]") ;32Bit 256 mal
[/autoit] [autoit][/autoit] [autoit]$palette = "0x"
[/autoit] [autoit][/autoit] [autoit]
Dim $z[256]
For $i = 0 To 223
$z[$i + 32] = $bar[$i]
$palette &= Hex($bar[$i],
Next
For $i = 224 To 255
$z[$i - 223] = $bar[$i]
$palette &= Hex($bar[$i],
Next
$bar = $z;~ ;_arraydisplay($bar)
[/autoit] [autoit][/autoit] [autoit]$hgui = GUICreate("Palette", 800, 500, -1, -1)
[/autoit] [autoit][/autoit] [autoit]
$pic = GUICtrlCreatePic(FileOpenDialog("Datei laden", @ScriptDir, "(*.jpg;*.bmp;*.png)", 16), 0, 0, 400, 400)
$hdc = _WinAPI_GetDC(WinGetHandle($hgui))GUISetState()
[/autoit] [autoit][/autoit] [autoit]
;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 pictureFor $x = 0 To 400
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
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
NextDo
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
ToolTip(Hex(PixelGetColor(MouseGetPos(0), MouseGetPos(1), $hgui))) ;anzeige der Pixelcolor unter dem Mauszeiger
Until GUIGetMsg() = -3Func pix($dc, $x, $y, $color) ;pixel mit color an koordinaten setzen
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
DllCall($gdi32, "long", "SetPixel", "long", $dc, "long", $x, "long", $y, "long", $color)
EndFunc ;==>pixFunc endcolor($r, $g, $b)
[/autoit] [autoit][/autoit] [autoit]
$red[1] = $r
$green[1] = $g
$blue[1] = $b
EndFunc ;==>endcolorFunc startcolor($r, $g, $b)
[/autoit]
$red[0] = $r
$green[0] = $g
$blue[0] = $b
EndFunc ;==>startcolor -
UEZ Genau! Danke!
-
Schade, jetzt hat ich auch extra noch was gemacht, war wohl zu langsam
Naja fürs nächste mal:
Spoiler anzeigen
[autoit]#include <Color.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
Opt("GUIOnEventMode", 1)
OnAutoItExitRegister("__GDIPlus_Shutdown")
_GDIPlus_Startup()Global $iWidth = 400, $iHeight = 400
[/autoit] [autoit][/autoit] [autoit]$hGUI = GUICreate("", $iWidth, $iHeight)
[/autoit] [autoit][/autoit] [autoit]
GUISetOnEvent(-3, "OnEvent_Eventhandler")
GUIRegisterMsg($WM_PAINT, "WM_PAINT")$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
[/autoit] [autoit][/autoit] [autoit]
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic)
$hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)GUISetState()
[/autoit] [autoit][/autoit] [autoit]
While 1 * Sleep(10)
WM_PAINT()
WEndFunc OnEvent_Eventhandler()
[/autoit] [autoit][/autoit] [autoit]
Exit
EndFunc ;==>OnEvent_EventhandlerFunc WM_PAINT()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_GraphicsClear($hBackbuffer, 0xFF000000 + _NewColor())
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iWidth, $iHeight)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_PAINTFunc __GDIPlus_Shutdown()
[/autoit] [autoit][/autoit] [autoit]
_GDIPlus_BrushDispose($hBrush)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
EndFunc ;==>__GDIPlus_ShutdownFunc _NewColor()
[/autoit]
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 ;==>_NewColorPS: Kann unnützes Zeug mit drin sein. ich hab ein GDI - Abbrev
//EDIT: Scheine, das Thema eh verfehlt zu haben
-
SEuBo
[autoit]
Sieht trotzdem schick aus
Ich würde bei __GDIPlus_Shutdown() allerdings noch_GDIPlus_GraphicsDispose($hBackbuffer)
[/autoit]
hinzufügen.