从文件中创建位图对象
#Include <GDIPlus.au3>
_GDIPlus_BitmapCreateFromFile($sFileName)
$sFileName | 位图文件路径 |
成功: | 位图对象句柄 |
失败: | 返回 0 |
在MSDN中搜索
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
_Main()
Func _Main()
Local $hGUI, $hBMP, $hBitmap, $hGraphic, $hImage, $iX, $iY, $hClone
; 创建 GUI
$hGUI = GUICreate("GDI+", 400, 300)
GUISetState()
; 初始化 GDI+ 库
_GDIPlus_Startup()
; 捕获到 32 位位图
$hBMP = _ScreenCapture_Capture("")
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
; 创建 24 位位图副本
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
$hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF24RGB)
; 保存位图到文件
_GDIPlus_ImageSaveToFile($hClone, @MyDocumentsDir & "\GDIPlus_Image.bmp")
; 清理资源
_GDIPlus_BitmapDispose($hClone)
_GDIPlus_BitmapDispose($hImage)
_WinAPI_DeleteObject($hBMP)
; 在 GUI 中描绘位图
$hBitmap = _GDIPlus_BitmapCreateFromFile(@MyDocumentsDir & "\GDIPlus_Image.bmp")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
; 清理资源
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_BitmapDispose($hBitmap)
; 关闭 GDI+ 库
_GDIPlus_Shutdown()
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main