本帖最后由 cola 于 2017-7-23 23:44 编辑
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
Global $exit = 0 ; 按f2 可以結束程式
HotKeySet("{F2}", "end")
func end()
$exit= 1
EndFunc
exp1()
Func exp1()
Global $exit = 0 ; 先設定可以執行迴圈
Local $hGUI, $hBMP, $hBitmap, $hGraphic
Local $hGUI = GUICreate("demo", 566, 100) ;黑白視窗的大小 前面是寬度,後面是高度
_GDIPlus_Startup()
while $exit=0 ;當$exit 這個變數 不等於 0 的時候就跳出
_ScreenCapture_SetBMPFormat (4)
$hBMP = _ScreenCapture_Capture("", 0, 400, 566, 500) ;抓取部份螢幕變成黑白 左上和右下的座標
Local $iW = 566, $iH = 100 ;get width and height of the image ;抓取區域的大小 寬 和 高
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
_WinAPI_DeleteObject($hBMP)
Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iW, $iH, BitOR($GDIP_ILMWRITE, $GDIP_ILMREAD), $GDIP_PXF32ARGB) ;locks a portion of a bitmap for reading and writing. More infor at http://msdn.microsoft.com/en-us/library/windows/desktop/ms536298(v=vs.85).aspx
Local $iScan0 = DllStructGetData($tBitmapData, "Scan0") ;get scan0 (pixel data) from locked bitmap
; Local $iSearchPixel = Int(0xFF000080), $iReplaceColor = 0xFF000000 ;color format 0xAARRGGBB
Local $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0)
Local $iPixel, $iRowOffset
For $iY = 0 To $iH - 1
$iRowOffset = $iY * $iW + 1
For $iX = 0 To $iW - 1 ;get each pixel in each line and row
$iPixel = DllStructGetData($tPixel, 1, $iRowOffset + $iX) ;get pixel color
$iR = BitShift(BitAND($iPixel, 0x00FF0000), 16) ;extract red color channel ; 取出的顏色 紅色分量
$iG = BitShift(BitAND($iPixel, 0x0000FF00), 8) ;extract green color channel ; 取出的顏色 綠色分量
$iB = BitAND($iPixel, 0x000000FF) ;;extract blue color channel ; 取出的顏色 藍色分量
if $iR > 100 then $iReplaceColor=0xFFFFFFFF
if $iR < 100 then $iReplaceColor=0xFF000000
DllStructSetData($tPixel, 1, $iReplaceColor, $iRowOffset + $iX) ;compare and replace pixel color
Next
Next
_GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData) ;unlocks a portion of a bitmap that was locked by _GDIPlus_BitmapLockBits
GUISetState(@SW_SHOW)
Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a Graphics object from a window handle
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $iW, $iH) ;copy manipulated image to graphics handle
WEnd
;cleanup resources
; _GDIPlus_ImageDispose($hImage)
; _GDIPlus_GraphicsDispose($hContext)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
GUIDelete($hGUI)
EndFunc ;==>Example |