Draw an Image object
#include <GDIPlus.au3>
_GDIPlus_GraphicsDrawImageRectRect ( $hGraphics, $hImage, $nSrcX, $nSrcY, $nSrcWidth, $nSrcHeight, $nDstX, $nDstY, $nDstWidth, $nDstHeight [, $pAttributes = 0 [, $iUnit = 2]] )
$hGraphics | Handle to a Graphics object |
$hImage | Handle to an Image object |
$nSrcX | The X coordinate of the upper left corner of the source image |
$nSrcY | The Y coordinate of the upper left corner of the source image |
$nSrcWidth | Width of the source image |
$nSrcHeight | Height of the source image |
$nDstX | The X coordinate of the upper left corner of the destination image |
$nDstY | The Y coordinate of the upper left corner of the destination image |
$nDstWidth | Width of the destination image |
$nDstHeight | Height of the destination image |
$pAttributes | [optional] Pointer to an ImageAttributes structure that specifies the color and size attributes of the image to be drawn. The default value is NULL. |
$iUnit | [optional] Specifies the unit of measure for the image |
Success: | True |
Failure: | False and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPIP_ERR* see GPIPlusConstants.au3). |
Search GdipDrawImageRectRect in MSDN Library.
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>
Example()
Func Example()
_GDIPlus_Startup() ;initialize GDI+
Local Const $iWidth = 600, $iHeight = 600
Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
GUISetState(@SW_SHOW)
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
Local $pIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object
;create the color matrix used to adjust the colors of the image
Local $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(-1, -1, 0) ;use translation color matrix to create a blue scaled image
_GDIPlus_ImageAttributesSetColorMatrix($pIA, 0, True, $tColorMatrix) ;adjust the ImageAttribute color-key color matrix
Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ;create a GDI bitmap by capturing an area on desktop
Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
_WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth, $iHeight, $pIA) ;draw the bitmap while applying the color adjustment
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
;cleanup GDI+ resources
_GDIPlus_ImageAttributesDispose($pIA)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
EndFunc ;==>Example
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>
Global $g_hGUI, $g_hGfxCtxt, $g_hBitmap, $g_hBMP, $g_hGraphics
Example()
Func Example()
AutoItSetOption("GUIOnEventMode", 1)
_GDIPlus_Startup() ;initialize GDI+
Local Const $iWidth = 600, $iHeight = 600, $iBgColor = 0x303030 ;$iBGColor format RRGGBB
$g_hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
GUISetBkColor($iBgColor, $g_hGUI) ;set GUI background color
GUISetState(@SW_SHOW)
;create buffered graphics frame set for smoother gfx object movements
$g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;create a graphics object from a window handle
$g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $g_hGraphics)
$g_hGfxCtxt = _GDIPlus_ImageGetGraphicsContext($g_hBitmap)
Local Const $iW = 300, $iH = 300
Local $hHBmp = _ScreenCapture_Capture("", 4, @DesktopHeight - $iH, $iW + 4, @DesktopHeight) ;create a GDI bitmap by capturing an area on desktop
$g_hBMP = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
_WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
Local $iVectorX = Random(1.5, 2.5), $iVectorY = Random(1.5, 2.5) ;define x and y vector
Local $iX = 0.0, $iY = 0.0 ;define start coordinate
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Do
_GDIPlus_GraphicsClear($g_hGfxCtxt, 0xFF000000 + $iBgColor) ;clear bitmap for repaint
_GDIPlus_GraphicsDrawImageRectRect($g_hGfxCtxt, $g_hBMP, 0, 0, $iW, $iH, $iX, $iY, $iW / 2, $iH) ;draw bitmap to backbuffer by halving the width
_GDIPlus_GraphicsDrawImageRect($g_hGraphics, $g_hBitmap, 0, 0, $iWidth, $iHeight) ;copy drawn bitmap to graphics handle (GUI)
$iX += $iVectorX ;add x vector to current x position
$iY += $iVectorY ;add y vector to current y position
If $iX < 0 Or $iX > ($iWidth - $iW / 2) Then $iVectorX *= -1 ;when x border is reached reverse x vector
If $iY < 0 Or $iY > ($iHeight - $iH) Then $iVectorY *= -1 ;when y border is reached reverse y vector
Until Not Sleep(20) ;sleep 20 ms to avoid high cpu usage
EndFunc ;==>Example
Func _Exit()
;cleanup GDI+ resources
_GDIPlus_GraphicsDispose($g_hGfxCtxt)
_GDIPlus_GraphicsDispose($g_hGraphics)
_GDIPlus_BitmapDispose($g_hBitmap)
_GDIPlus_BitmapDispose($g_hBMP)
_GDIPlus_Shutdown()
GUIDelete($g_hGUI)
Exit
EndFunc ;==>_Exit