#include <GDIPlus.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1)
$hwnd = GUICreate("GDI+ Sample!", 500, 500)
GUISetOnEvent(-3, "close")
GUISetState()
$sFile = @ScriptDir & "\123.png"
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($sFile)
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
$bitmap = _GDIPlus_BitmapCreateFromGraphics(500, 500, $graphics); This is actually the buffer
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap); This is to access the buffer
$TextureBrush = _GDIPlus_CreateTextureTrans($hImage, 0.6)
$white = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
$x = 175
$y = 175
$d = 50
draw($x, $y)
Do
If _IsPressed("25") Then; Left arrow
$x -= 5
draw($x, $y)
EndIf
If _IsPressed("26") Then; up arrow
$y -= 5
draw($x, $y)
EndIf
If _IsPressed("27") Then; right arrow
$x += 5
draw($x, $y)
EndIf
If _IsPressed("28") Then; down arrow
$y += 5
draw($x, $y)
EndIf
If _IsPressed("44") Then; D KEY Decrease diameter of circle
$d -= 1
draw($x, $y)
EndIf
If _IsPressed("55") Then; U KEY increase diameter of circle
$d += 1
draw($x, $y)
EndIf
Sleep(50)
Until False
Func draw($x, $y)
_GDIPlus_GraphicsClear($backbuffer, 0xFFFF0000); Always start with a clean buffer!
_GDIPlus_GraphicsFillRect($backbuffer, $x, $y, 480, 480, $TextureBrush)
_GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, 500, 500); Present buffer to screen!
EndFunc ;==>draw
Func close()
;_GDIPlus_ImageSaveToFile($bitmap, @DesktopDir & "\TestWrite1.png")
;ShellExecute(@DesktopDir & "\TestWrite1.png")
_GDIPlus_BrushDispose($white)
_GDIPlus_BrushDispose($TextureBrush)
_GDIPlus_GraphicsDispose($graphics)
_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_BitmapDispose($bitmap)
_GDIPlus_ImageDispose ($hImage)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>close
;
; #FUNCTION# ============================================================================================
; Name...........: _GDIPlus_CreateTextureTrans
; Description ...: Creates a TextureBrush object based on an image, and sets image transparency property.
; Parameter
; $hImage - Pointer to the Image object.
; $nTrans - Value range from 0 (Zero for invisible) to 1.0 (fully opaque)
; $iX - Leftmost coordinate of the image portion to be used by this brush.
; $iY - Uppermost coordinate of the image portion to be used by this brush.
; $iWidth - Width of the brush and width of the image portion to be used by the brush.
; $iHeight - Height of the brush and height of the image portion to be used by the brush.
; Return - Handle (pointer) to the new created TextureBrush object.
Func _GDIPlus_CreateTextureTrans($hImage, $nTrans = 0.5, $iX = 0, $iY = 0, $iWidth = "", $iHeight = "")
Local $tColorMatrix, $x, $hImgAttrib, $iW = _GDIPlus_ImageGetWidth($hImage), $iH = _GDIPlus_ImageGetHeight($hImage)
If $iWidth = 0 Or $iWidth = "" Then $iWidth = $iW
If $iHeight = 0 Or $iHeight = "" Then $iHeight = $iH
;;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
Local $aResult = DllCall($ghGDIPDll, "int", "GdipCreateTextureIAI", "hwnd", $hImage, "ptr", $hImgAttrib, "int", $iX, "int", _
$iY, "int", $iWidth, "int", $iHeight, "ptr*", 0)
;clean up
DllCall($ghGDIPDll, "int", "GdipDisposeImageAttributes", "ptr", $hImgAttrib)
Return $aResult[7]
EndFunc ;==>_GDIPlus_CreateTextureTrans