Das hier ist eigentlich nur ein Beispielscript. ![]()
Es soll zeigen, wie man aus einer Bitmap (oder einem Teil davon) einen Brush erstellt.
Die Funktion habe ich aus der GDIP.au3, welche erweiterte GDI+ Funktionen enthält.
Morgen erstelle ich ein schöneres und übersichtlicheres Beispiel, wenn Bedarf besteht. ![]()
Spoiler anzeigen
#include <GDIPlus.au3>
#include <GUIConstants.au3>
$iGUIWidth = 400
$iGUIHeight = 400
$GUIColorBG = 0xFFFFFFFF
$iX = 50 ;X-Koordinate des rechteckigen Bitmap Ausschnitts
$iY = 50 ;Y-Koordinate des rechteckigen Bitmap Ausschnitts
$iX2 = 100 ;X-Koordinate der Ellipse
$iY2 = 100 ;Y-Koordinate der Ellipse
$iWidth = 50 ;Breite des rechteckigen Bitmap Ausschnitts
$iHeight = 50 ;Höhe des rechteckigen Bitmap Ausschnitts
$iWidth2 = 50 ;Breite der Ellipse
$iHeight2 = 50 ;Höhe der Ellipse
$hWnd = GUICreate("Test", $iGUIWidth, $iGUIHeight)
GUISetState()
_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics($iGUIWidth, $iGUIHeight, $hGraphic)
$hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hGraphic, $GUIColorBG)
_GDIPlus_GraphicsClear($hBuffer, $GUIColorBG)
$hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Test.png")
[/autoit] [autoit][/autoit] [autoit]$hTextureBrush = _GDIPlus_TextureCreate2($hImage, $iX, $iY, $iWidth, $iHeight)
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_GraphicsFillEllipse($hBuffer, $iX2, $iY2, $iWidth2, $iHeight2, $hTextureBrush)
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iGUIWidth, $iGUIHeight)
[/autoit] [autoit][/autoit] [autoit]While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_GraphicsDispose($hBuffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_BrushDispose($hTextureBrush)
_GDIPlus_Shutdown()
Exit
EndSwitch
WEnd
;Die Funktionen sind nicht von mir!!
; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_TextureCreate
; Description ...: Creates a TextureBrush object based on an image and a wrap mode
; Syntax.........: _GDIPlus_TextureCreate($hImage[, $iWrapMode = 0])
; Parameters ....: $hImage - Pointer to an Image object
; $iWrapMode - Wrap mode that specifies how repeated copies of an image are used to tile an area when it is
; +painted with the texture brush:
; |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 TextureBrush 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 .......: The size of the brush defaults to the size of the image, so the entire image is used by the brush
; After you are done with the object, call _GDIPlus_BrushDispose to release the object resources
; Related .......: _GDIPlus_BrushDispose
; Link ..........; @@MsdnLink@@ GdipCreateTexture
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_TextureCreate($hImage, $iWrapMode = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture", "hwnd", $hImage, "int", $iWrapMode, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[3]
EndFunc ;==>_GDIPlus_TextureCreate
; #FUNCTION# ====================================================================================================================
; Name...........: _GDIPlus_TextureCreate2
; Description ...: Creates a TextureBrush object based on an image, a wrap mode and a defining rectangle
; Syntax.........: _GDIPlus_TextureCreate2($hImage, $nX, $nY, $nWidth, $nHeight[, $iWrapMode = 0])
; Parameters ....: $hImage - Pointer to an Image object
; $nX - Leftmost coordinate of the image portion to be used by this brush
; $nY - Uppermost coordinate of the image portion to be used by this brush
; $nWidth - Width of the brush and width of the image portion to be used by the brush
; $nHeight - Height of the brush and height of the image portion to be used by the brush
; $iWrapMode - Wrap mode that specifies how repeated copies of an image are used to tile an area when it is
; +painted with the texture brush:
; |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 TextureBrush 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@@ GdipCreateTexture2
; Example .......; No
; ===============================================================================================================================
Func _GDIPlus_TextureCreate2($hImage, $nX, $nY, $nWidth, $nHeight, $iWrapMode = 0)
Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateTexture2", "hwnd", $hImage, "int", $iWrapMode, "float", $nX, "float", $nY, "float", $nWidth, "float", $nHeight, "int*", 0)
If @error Then Return SetError(@error, @extended, 0)
$GDIP_STATUS = $aResult[0]
Return $aResult[7]
EndFunc ;==>_GDIPlus_TextureCreate2