_GDIPlus_GraphicsReflectImageRect

  • Hatte heute Langeweile und ein GDI+ Beispiel mit Spiegeleffekt und abfallender Transparents geschrieben.

    Danksagungen gehen natürlich an:
    Siao, Malkey (für die super Funktion) und GTA Spider, von dem ich das Bild 'missbraucht' hab.
    Hoffe, du hast nichts dagegen. ;)

    Edit:
    So, hab das Script umgeschrieben und das ganze zu einen Mausverfolger ummodeliert. Sozusagen als Beispiel.
    Den Mausverfolger kann man mit esc und linken strg Taste ausschschalten.

    Einstellbare Einrückung pro Zeile nach links hinzugefügt.

    Die Funktion selbst ist nun auch Universeller.

    ACHTUNG: Der Parameter $dheight sollte besser mit -1 übergeben werden, weil da noch ein Bug drinnen ist.
    Bin noch am Basteln. ;)

    Screenshot:
    [Blockierte Grafik: http://img697.imageshack.us/img697/7633/gd…icsreflecti.png]

    Beispiel
    [autoit]

    #NoTrayIcon
    #include <GDIPlus.au3>
    #include <Misc.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $hWnd, $hGraphic, $hBitmap, $backbuffer, $hImage
    Global $ScreenDc, $dc, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend, $tPoint, $pPoint, $gdibitmap
    Global $title = "GDI+ Beispiel: Bilder spiegeln", _
    $user32 = DllOpen("user32.dll"), _
    $width = 500, _
    $height = 130

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

    Global $reflect, $MousePos

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

    If Not FileExists(@ScriptDir & "\autoit_logo_gtaspider.png") Then FileInstall("D:\_bnt8x-dta\Eigene Dateien\Eigene Bilder\AutoIt.de Logo\autoit_logo_gtaspider.png", @ScriptDir & "\autoit_logo_gtaspider.png")

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

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

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

    _Startup()
    _GDIPlus_GraphicsClear($backbuffer, 0x00000000)
    _GDIPlus_GraphicsDrawImageRect($backbuffer, $hImage, 16, 0, 468, 60)
    _GDIPlus_GraphicsReflectImageRect($backbuffer, $hImage, 16, 70, -1, 40, 0.7)
    $reflect = _GDIPlus_BitmapCloneArea($backbuffer, 0, 0, 700, 700, $GDIP_PXF64PARGB)
    $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($hWnd, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2)
    _WinAPI_DeleteObject($gdibitmap)
    _GDIClose()

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

    GUISetState()

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

    While 1
    $MousePos = MouseGetPos()
    WinMove($title, "", $MousePos[0], $MousePos[1])
    If _IsPressed("1B", $user32) And _IsPressed("A2", $user32) Then _Close()
    Sleep(10)
    WEnd

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

    Func _Startup()
    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetSmoothingMode($backbuffer, 4)
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\autoit_logo_gtaspider.png")

    [/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", 255)
    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($backbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    If @Compiled Then FileDelete(@ScriptDir & "\autoit_logo_gtaspider.png")
    EndFunc

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

    Func _Close()
    DllClose($user32)
    GUISetState(@SW_MINIMIZE, $hWnd)
    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]
    _GDIPlus_GraphicsReflectImageRect
    [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 Startzeichenpunkt; #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]

    Bild, au3 und exe sind im Anhang.

    Dateien

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%

    4 Mal editiert, zuletzt von H2112 (5. Februar 2010 um 22:51)

  • Bei mir stürzt das Skript ab:

    Problemsignatur:
    Problemereignisname: APPCRASH
    Anwendungsname: AutoIt3.exe
    Anwendungsversion: 3.3.4.0
    Anwendungszeitstempel: 4b509352
    Fehlermodulname: GDIPlus.dll
    Fehlermodulversion: 5.2.6002.18005
    Fehlermodulzeitstempel: 49e036f1
    Ausnahmecode: c0000005
    Ausnahmeoffset: 000464c9
    Betriebsystemversion: 6.0.6002.2.2.0.256.4 -> Vista x32
    Gebietsschema-ID: 1031
    Zusatzinformation 1: 5a39
    Zusatzinformation 2: cdfd3cb33466d6ffbb26c3edc7aaf68f
    Zusatzinformation 3: 54f0
    Zusatzinformation 4: 2de12d5a49c981685da61adf0664ddf7

    Liegt an der Zeile 24: $reflect = _GDIPlus_BitmapCloneArea($backbuffer, 0, 0, 700, 700, $GDIP_PXF64PARGB) -> auskommentieren, dann läuft das Skript wieder!

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    3 Mal editiert, zuletzt von UEZ (15. Februar 2010 um 14:46)

  • Bei mir läuft das Script eigentlich auch einwandfrei.

    Windows XP Home Edition, Service Pack 3

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%