GDIPlus Text spiegeln

  • Kann man mit GDIPlus einen Text zeichnen (wie in dem Beispiel aus der Hilfe) und diesen dann mit abnehmender Transparenz spiegeln?

    Spoiler anzeigen
    [autoit]


    #include <GuiConstantsEx.au3>
    #include <GDIPlus.au3>

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

    Opt('MustDeclareVars', 1)

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

    _Main()

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

    Func _Main()
    Local $hGUI, $hGraphic

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

    ; Create GUI
    $hGUI = GUICreate("GDI+", 400, 300)
    GUISetState()

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

    ; Draw a string
    _GDIPlus_Startup ()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    _GDIPlus_GraphicsDrawString ($hGraphic, "Hello world", 140, 110)

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

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

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

    ; Clean up resources
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

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

    EndFunc ;==>_Main

    [/autoit] [autoit][/autoit] [autoit][/autoit]
  • Ja, aber halt mit Text und ohne externes Bild. Wäre nett, wenn mir jemand helfen könnte, denn mit GDIplus hab' ich noch nicht so viel Erfahrung.

  • Spoiler anzeigen
    [autoit]


    ;Example by UEZ
    ;#NoTrayIcon
    #include <GDIPlus.au3>
    #include <Misc.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $hWnd, $hGraphic, $hBitmap, $hBackbuffer, $hImage
    Global $ScreenDc, $dc, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend, $tPoint, $pPoint, $gdibitmap
    Global $title = "GDI+ Beispiel: Text spiegeln", _
    $width = 500, _
    $height = 130

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

    Global $reflect, $MousePos

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

    $hWnd = GUICreate($title, $width, $height, -1, -1, 0x80000000, BitOR(0x00000080, 0x00080000, 0x00000008))

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

    _Startup()
    _GDIPlus_GraphicsClear($hBackbuffer, 0x00000000)
    Draw_Text($hBackbuffer, "Spiegel Schrift", $width, $height)

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

    _GDIPlus_GraphicsReflectImageRect($hBackbuffer, $hBitmap, 0, 60, -1, 40, 0)

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

    $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($hWnd, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($gdibitmap)
    _GDIClose()
    GUISetOnEvent(-3, "_Close")
    GUISetState()

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

    While Sleep(100000)
    WEnd

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

    Func Draw_Text($hGFX, $text, $w, $h, $fs = 40, $fn = "Comic Sans MS", $fc = 0xFF0000A0, $fa = 1)
    $hBrush = _GDIPlus_BrushCreateSolid($fc)
    $hFamily = _GDIPlus_FontFamilyCreate($fn)
    $hFont = _GDIPlus_FontCreate($hFamily, $fs)
    $hLayout = _GDIPlus_RectFCreate(0, 0, $w, $h)
    $hStringFormat = _GDIPlus_StringFormatCreate()
    _GDIPlus_StringFormatSetAlign($hStringFormat, $fa)
    _GDIPlus_GraphicsDrawStringEx($hGFX, $text, $hFont, $hLayout, $hStringFormat, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_StringFormatDispose($hStringFormat)
    EndFunc

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

    Func _Startup()
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

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

    $ScreenDc = _WinAPI_GetDC($hWnd)
    $dc = _WinAPI_CreateCompatibleDC($ScreenDc)

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

    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $width)
    DllStructSetData($tSize, "Y", $height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", 0xFF)
    DllStructSetData($tBlend, "Format", 1)
    $tPoint = DllStructCreate($tagPOINT)
    $pPoint = DllStructGetPtr($tPoint)
    DllStructSetData($tPoint, "X", 0)
    DllStructSetData($tPoint, "Y", 0)
    EndFunc

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

    Func _GDIClose()
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    EndFunc

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

    Func _Close()
    Exit
    EndFunc

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

    ; #FUNCTION# ==========================================================================================================
    ; Name...........: _GDIPlus_GraphicsReflectImageRect
    ; Description ...: Spiegelt ein Bildobjekt mit abfallender Transparents und einstellbarer Schräge.
    ; Syntax.........: _GDIPlus_GraphicsReflectImageRect($hGraphic, $hImage, $xpos, $ypos, [$dwidth, [$dheight, [$divx]]])
    ; Parameters ....: $hGraphics - Handle zu einem Graphicobjekt
    ; $hImage - Handle zu einem Bildobjekt
    ; $xpos - Die X Koordinate des Startzeichenpunktes
    ; $ypos - Die Y Koordinate des Startzeichenpunktes
    ; $dwidth - Breite des zu zeichnenden Bildes
    ; $dheight - Höhe des zu zeichnenden Bildes (!FEHLERHAFT)
    ; $divx - Die Anzahl der Pixel, die pro Zeile nach links eingerückt werden
    ; Return values .: Success - True
    ; Failure - @error
    ; Author ........: h2112
    ; Remarks .......: Die Funktion _GDIPlus_GraphicsDrawImageRectRectTrans wird benötigt
    ;======================================================================================================================
    Func _GDIPlus_GraphicsReflectImageRect($hGraphic, $hImage, $xpos, $ypos, $dwidth = -1, $dheight = -1, $divx = 0.7)
    Local $height, $width, $clone, $stat, $check
    Local $divy, $divtrans, $trans, $x, $y, $olddivy

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

    $height = _GDIPlus_ImageGetHeight($hImage)
    $width = _GDIPlus_ImageGetWidth($hImage)

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

    If $dheight = -1 Then $dheight = $height
    If $dwidth = -1 Then $dwidth = $width

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

    $divtrans = 255 / $height
    $divy = $dheight / $height

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

    For $i = $height To 0 Step -1
    $trans = 1 / 255 * $divtrans * $i
    $x = $divx * ($height - $i)
    $y = $divy * ($height - $i)
    If Int($y) <> Int($divy) * ($height - $i) + $stat Then
    $stat += 1
    $check = 1
    $olddivy = $divy
    $divy += Int($y) - Int($divy) * ($height - $i) + $stat
    EndIf
    $clone = _GDIPlus_BitmapCloneArea($hImage, 0, $i, $width, 1, $GDIP_PXF64PARGB)
    _GDIPlus_GraphicsDrawImageRectRectTrans($hGraphic, $clone, 0, 0, $width, $height, $xpos - $x, $y + $ypos, $dwidth, $divy, "", $trans)
    If $check = 1 Then
    $divy = $olddivy
    $check = 0
    EndIf
    Next
    If Not @error Then
    Return True
    Else
    Return @error
    EndIf
    EndFunc

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

    ; #FUNCTION# ===================================================================================================
    ; Name...........: _GDIPlus_GraphicsDrawImageRectRectTrans
    ; Description ...: Draw an Image object with transparency
    ; Syntax.........: _GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hImage, $iSrcX, $iSrcY, [$iSrcWidth, _
    ; [$iSrcHeight, [$iDstX, [$iDstY, [$iDstWidth, [$iDstHeight[, [$iUnit = 2]]]]]]])
    ; Parameters ....: $hGraphics - Handle to a Graphics object
    ; $hImage - Handle to an Image object
    ; $iSrcX - The X coordinate of the upper left corner of the source image
    ; $iSrcY - The Y coordinate of the upper left corner of the source image
    ; $iSrcWidth - Width of the source image
    ; $iSrcHeight - Height of the source image
    ; $iDstX - The X coordinate of the upper left corner of the destination image
    ; $iDstY - The Y coordinate of the upper left corner of the destination image
    ; $iDstWidth - Width of the destination image
    ; $iDstHeight - Height of the destination image
    ; $iUnit - Specifies the unit of measure for the image
    ; $nTrans - Value range from 0 (Zero for invisible) to 1.0 (fully opaque)
    ; Return values .: Success - True
    ; Failure - False
    ; Author ........: Siao
    ; Modified.......: Malkey
    ; Remarks .......:
    ; Related .......:
    ; Link ..........; http://www.autoitscript.com/forum/index.ph…ndpost&p=517195
    ; Example .......; Yes
    Func _GDIPlus_GraphicsDrawImageRectRectTrans($hGraphics, $hImage, $iSrcX, $iSrcY, $iSrcWidth = "", $iSrcHeight = "", _
    $iDstX = "", $iDstY = "", $iDstWidth = "" , $iDstHeight = "", $iUnit = 2, $nTrans = 1)
    Local $tColorMatrix, $x, $hImgAttrib, $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage)
    If $iSrcWidth = 0 or $iSrcWidth = "" Then $iSrcWidth = $iW
    If $iSrcHeight = 0 or $iSrcHeight = "" Then $iSrcHeight = $iH
    If $iDstX = "" Then $iDstX = $iSrcX
    If $iDstY = "" Then $iDstY = $iSrcY
    If $iDstWidth = "" Then $iDstWidth = $iSrcWidth
    If $iDstHeight = "" Then $iDstHeight = $iSrcHeight
    If $iUnit = "" Then $iUnit = 2
    ;;create color matrix data
    $tColorMatrix = DllStructCreate("float[5];float[5];float[5];float[5];float[5]")
    ;blending values:
    $x = DllStructSetData($tColorMatrix, 1, 1, 1) * DllStructSetData($tColorMatrix, 2, 1, 2) * DllStructSetData($tColorMatrix, 3, 1, 3) * _
    DllStructSetData($tColorMatrix, 4, $nTrans, 4) * DllStructSetData($tColorMatrix, 5, 1, 5)
    ;;create an image attributes object and update its color matrix
    $hImgAttrib = DllCall($ghGDIPDll, "int", "GdipCreateImageAttributes", "ptr*", 0)
    $hImgAttrib = $hImgAttrib[1]
    DllCall($ghGDIPDll, "int", "GdipSetImageAttributesColorMatrix", "ptr", $hImgAttrib, "int", 1, _
    "int", 1, "ptr", DllStructGetPtr($tColorMatrix), "ptr", 0, "int", 0)
    ;;draw image into graphic object with alpha blend
    DllCall($ghGDIPDll, "int", "GdipDrawImageRectRectI", "hwnd", $hGraphics, "hwnd", $hImage, "int", $iDstX, "int", _
    $iDstY, "int", $iDstWidth, "int", $iDstHeight, "int", $iSrcX, "int", $iSrcY, "int", $iSrcWidth, "int", _
    $iSrcHeight, "int", $iUnit, "ptr", $hImgAttrib, "int", 0, "int", 0)
    ;;clean up
    DllCall($ghGDIPDll, "int", "GdipDisposeImageAttributes", "ptr", $hImgAttrib)
    Return
    EndFunc ;==>_GDIPlus_GraphicsDrawImageRectRectTrans

    [/autoit]

    Ist eine Modifikation des Beispiels von H2112: _GDIPlus_GraphicsReflectImageRect


    Gruß,
    UEZ ;)

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Danke, genau sowas hab' ich gesucht! :thumbup:
    Kann man das auch direkt in eine GUI ohne transparenten Hintergrund zeichnen? Ich kenn' mich mit WinApi leider überhaupt nicht aus.

    Einmal editiert, zuletzt von xp_fan (28. Februar 2010 um 10:43)