图片截图(已解决)
本帖最后由 xymc 于 2019-9-8 22:29 编辑Local $pic = @HomeDrive&"\Source.bmp"
C盘里面有个图片,我想截取图片里面某个区域(300, 230, 350, 260)的图片.
查找了一下帮助,只找到_ScreenCapture_Capture这个函数,捕捉屏幕的,请教下有没有截取图片某个区域的方法?
谢谢版主,答案在4楼
_GDIPlus_GraphicsDrawImageRectRect afan 发表于 2019-9-6 20:30
_GDIPlus_GraphicsDrawImageRectRect
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
Local $pic = @HomeDrive&"\Source.bmp"
_Main()
Func _Main()
Local $hGUI2, $hImage, $hGraphic2
; 创建 GUI
$hGUI2 = GUICreate("Zoomed", 400, 300, 0, 400)
GUISetState()
; 初始化 GDI+ 库并加载图像
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($pic)
$hGraphic2 = _GDIPlus_GraphicsCreateFromHWND($hGUI2)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic2, $hImage, 300, 230, 200, 200, 300, 230, 200, 200)
; 释放资源
_GDIPlus_GraphicsDispose($hGraphic2)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
请教下怎么保存截取下来的这个图片?保存为BMP格式 方法有很多,这只是其中一种
#include <GDIPlus.au3>
Local $pic = @HomeDrive & "\Source.bmp"
_ImageCut($pic, 300, 230, 50, 30, $pic & '_1.bmp')
Func _ImageCut($ImgFile, $ix, $iy, $iw, $ih, $ImgFileNew)
_GDIPlus_Startup()
Local $hImage = _GDIPlus_ImageLoadFromFile($ImgFile)
Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hImage)
Local $hBMPNew = _GDIPlus_BitmapCreateFromGraphics($iw, $ih, $hGraphics)
Local $hGraphicNew = _GDIPlus_ImageGetGraphicsContext($hBMPNew)
_GDIPlus_GraphicsDrawImageRectRect($hGraphicNew, $hImage, $ix, $iy, $iw, $ih, 0, 0, $iw, $ih)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_GraphicsDispose($hGraphicNew)
_GDIPlus_ImageSaveToFile($hBMPNew, $ImgFileNew)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_ImageDispose($hBMPNew)
_GDIPlus_Shutdown()
EndFunc ;==>_ImageCut xymc 发表于 2019-9-6 20:59
#include
#include
#include
学习学习。收藏一下。 afan大神真是厉害
页:
[1]