本帖最后由 nmgwddj 于 2011-11-29 20:21 编辑
如下代码,GUI大小是根据桌面分辨率创建的,用_GDIPlus_GraphicsDrawImage绘制_ScreenCapture_Capture捕捉的结果是可以正常显示的。
而用_GDIPlus_BitmapCreateFromFile创建图像显示却超出了GUI的范围,图片被拉伸了。不知道什么原因,希望指点#include <GDIPlusEx.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPIEX.au3>
Opt('MustDeclareVars', 1)
_Example()
Func _Example()
Local $hGUI
Local $hBitmap, $hBmp, $hGraphics, $hImage
Local $iColor, $iX, $iY, $iImageWidth, $iImageHeight
Local $aSize
; 初始化GDI+
_GDIPlus_Startup()
; 创建GUI窗体, 按ESC退出
$hGUI = GUICreate("", @DesktopWidth, @DesktopHeight)
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hBmp = _ScreenCapture_Capture("", 0, 0, -1, -1, False)
; 用GDI位图对象创建GDI+位图对象
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
$aSize = _GDIPlus_ImageGetDimension($hBitmap)
$iColor = $GDIP_DARKSEAGREEN
$hImage = _GDIPlus_BitmapCreateFromFile('Wallpaper.jpg');从文件中创建一个位图对象
#cs
$iImageWidth = $aSize[0]
$iImageHeight = $aSize[1]
For $iX = 0 To $iImageWidth Step 16
For $iY = 0 To $iImageHeight Step 16
_GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, $iColor)
Next
Next
#ce
GUISetState()
; 绘制选定的屏幕捕捉
_GDIPlus_GraphicsDrawImage($hGraphics, $hImage, 0, 0)
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
; 清除资源
_GDIPlus_ImageDispose($hBitmap)
_WinAPI_DeleteObject($hBmp)
_GDIPlus_GraphicsDispose($hGraphics)
; 关闭GDI+库
_GDIPlus_Shutdown()
EndFunc ;==>_Example
|