Hex 6 in Hex 8 umwandeln?

  • Guten Abend,

    ich hab hier eine Funktion:

    Spoiler anzeigen
    [autoit]

    Func ColorGradient($hInitialColor, $hFinalColor, $iReturnSize)
    $hInitialColor = Hex($hInitialColor, 6)
    $hFinalColor = Hex($hFinalColor, 6)

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

    Local $iRed1 = Dec(StringLeft($hInitialColor, 2))
    Local $iGreen1 = Dec(StringMid($hInitialColor, 3, 2))
    Local $iBlue1 = Dec(StringMid($hInitialColor, 5, 2))

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

    Local $iRed2 = Dec(StringLeft($hFinalColor, 2))
    Local $iGreen2 = Dec(StringMid($hFinalColor, 3, 2))
    Local $iBlue2 = Dec(StringMid($hFinalColor, 5, 2))

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

    Local $iPlusRed = ($iRed2 - $iRed1) / ($iReturnSize - 1)
    Local $iPlusBlue = ($iBlue2 - $iBlue1) / ($iReturnSize - 1)
    Local $iPlusGreen = ($iGreen2 - $iGreen1) / ($iReturnSize - 1)

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

    Dim $iColorArray[$iReturnSize]
    For $i = 0 To $iReturnSize - 1
    $iNowRed = Floor($iRed1 + ($iPlusRed * $i))
    $iNowBlue = Floor($iBlue1 + ($iPlusBlue * $i))
    $iNowGreen = Floor($iGreen1 + ($iPlusGreen * $i))
    $iColorArray[$i] = Dec(Hex($iNowRed, 2) & Hex($iNowGreen, 2) & Hex($iNowBlue, 2))
    Next
    Return ($iColorArray)
    EndFunc ;==>ColorGradient

    [/autoit]

    dass einen Farbverlauf von Farbe a nach b berechnet und alle einzelne Farben als Array zurück gibt. Also die Rückgabewerte sind z.b. 3881263. Da ich diesen Farbverlauf für ein GDI+ Script brauche, muss ich das in so etwas umwandeln: 0xFF3A4FF6. Nun ich komm leider die ganze Zeit schon nicht drauf, wie man aus einer Zahl soetwas macht.

    Hier ein Stück aus meinem Code:

    Spoiler anzeigen
    [autoit]

    Local $AnzahlLinien = ($Hoehe - 7) + 2
    Local $Array = ColorGradient(RandomColor(), RandomColor(), $AnzahlLinien)

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

    Local $pen = _GDIPlus_PenCreate("0xFF" & $Array[0])

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

    _GDIPlus_GraphicsDrawLine($capGraph, 3, 2, $breite - 4, 2, $pen)

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

    For $i = 0 To $Hoehe - 7
    $pen = _GDIPlus_PenCreate("0xFF" & $Array[$i + 1])
    _GDIPlus_GraphicsDrawLine($capGraph, 2, 3 + $i, $breite - 3, 3 + $i, $pen)
    Next

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

    $pen = _GDIPlus_PenCreate("0xFF" & $Array[$AnzahlLinien - 1])
    _GDIPlus_GraphicsDrawLine($capGraph, 3, $Hoehe - 3, $breite - 4, $Hoehe - 3, $pen)

    [/autoit]

    Ich hab bei Zeile 9 versucht die "0xFF" einfach als String anzuhängen, aber das funktioniert nicht.

  • Kann es sein, dass der 6 stellige Hex String ein "0x" vorne stehen hat? Wenn ja musst du natürlich noch mit StringTrimLeft diese 2 abschneiden. ;)
    "0xFF" anhängen klappt bei mir nämlich prima. ?(

    Ach ja:

    Spoiler anzeigen
    [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GDIPlus_LineBrushCreate
    ; Description ...: Creates a LinearGradientBrush object from a set of boundary points and boundary colors
    ; Syntax.........: _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2[, $iWrapMode = 0])
    ; Parameters ....: $nX1 - X coordinate of the starting point of the gradient. The starting boundary line passes through the
    ; +starting point
    ; $nY1 - Y coordinate of the starting point of the gradient. The starting boundary line passes through the
    ; +starting point
    ; $nX2 - X coordinate of the ending point of the gradient. The ending boundary line passes through the
    ; +ending point
    ; $nY2 - Y coordinate of the ending point of the gradient. The ending boundary line passes through the
    ; +ending point
    ; $iARGBClr1 - Alpha, Red, Green and Blue components of the starting color of the line
    ; $iARGBClr2 - Alpha, Red, Green and Blue components of the ending color of the line
    ; $iWrapMode - Wrap mode that specifies how areas filled with the brush are tiled:
    ; |0 - Tiling without flipping
    ; |1 - Tiles are flipped horizontally as you move from one tile to the next in a row
    ; |2 - Tiles are flipped vertically as you move from one tile to the next in a column
    ; |3 - Tiles are flipped horizontally as you move along a row and flipped vertically as you move along a column
    ; |4 - No tiling takes place
    ; Return values .: Success - Pointer to a new LinearGradientBrush 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_BrushDispose to release the object resources
    ; Related .......: _GDIPlus_BrushDispose
    ; Link ..........; @@MsdnLink@@ GdipCreateLineBrush
    ; Example .......; No
    ; ===============================================================================================================================
    Func _GDIPlus_LineBrushCreate($nX1, $nY1, $nX2, $nY2, $iARGBClr1, $iARGBClr2, $iWrapMode = 0)
    Local $tPointF1, $pPointF1
    Local $tPointF2, $pPointF2
    Local $aResult

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

    $tPointF1 = DllStructCreate("float;float")
    $pPointF1 = DllStructGetPtr($tPointF1)
    $tPointF2 = DllStructCreate("float;float")
    $pPointF2 = DllStructGetPtr($tPointF2)

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

    DllStructSetData($tPointF1, 1, $nX1)
    DllStructSetData($tPointF1, 2, $nY1)
    DllStructSetData($tPointF2, 1, $nX2)
    DllStructSetData($tPointF2, 2, $nY2)

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

    $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateLineBrush", "ptr", $pPointF1, "ptr", $pPointF2, "uint", $iARGBClr1, "uint", $iARGBClr2, "int", $iWrapMode, "int*", 0)

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

    If @error Then Return SetError(@error, @extended, 0)
    $GDIP_STATUS = $aResult[0]
    Return $aResult[6]
    EndFunc ;==>_GDIPlus_LineBrushCreate

    [/autoit]


    Lineare Farbverläufe lassen sich auch effektiver erstellen :D.

    Edit: Mir fällt gerade auf, dass du in deinem Script ziemlich viele Pens erstellst, aber keinen einzigen mit PenDispose wieder löschst. Das solltest du entweder korrigieren oder du nimmst die Funktion die ich oben geschrieben habe :P .

  • ich würde das so machen:

    [autoit]

    MsgBox(0, '', "0xFF"&StringTrimLeft(Hex(3881263),2))

    [/autoit]

    MfG Schnuffel

    "Sarkasmus ist die niedrigste Form des Witzes, aber die höchste Form der Intelligenz."
    Val McDermid

    über mich...

    ich habe meine Erfahrungen hauptsächlich gesammelt in (grobe Übersicht):

    - RibbonBar Automation
    - MySQL Nutzung
    - GUIs in vielerlei Ausprägung
    - Nutzung von Powershell / Batch in AutoIt
    - Windows Automatisierung

    außerhalb von AutoIt:

    - Sprachen: PS, Batch, php, html(5), javascript, (perl eingeschränkt), vbs
    - Powershell (AD, WPF inkl. Multi-Threading, ...)
    - Deployment-Automatisierung ohne SCCM
    - Office-Nutzung mit COM-Object (AutoIt, PowerShell)
    - ActiveDirectory und alles was damit zusammenhängt
    - Hyper-V Clustering (Converged / Hyper Converged)
    - Serverhardware (Konfiguration, Aufbau, Architektur, Betrieb)

    Lieblingsthema:

    günstige Automatisierung von Vorgängen, für die andere Firmen viel Geld nehmen

    more to come ...