Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GDIPlus.au3>
- #include <WinAPI.au3>
- #include <Memory.au3>
- #include <WindowsConstants.au3>
- HotKeySet("{ESC}","_exit")
- Func _exit()
- Exit
- EndFunc
- _GDIPlus_Startup()
- Global $screenDC
- Global $gfxContext, $hDC, $hHBitmap, $buffer, $hPen
- Global $GUI, $GUI_W = 400, $GUI_H = 400
- ; chay notepad
- If ProcessExists("mspaint.exe") = False Then Run("mspaint.exe")
- $hwnd = WinWait("[CLASS:MSPaintApp]")
- $screenDC = _WinAPI_GetDc($hwnd) ; neu muon chup man hinh thi cho $hwnd = 0
- $GUI = GUICreate("", $GUI_W, $GUI_H)
- GUISetState()
- WinSetOnTop($GUI, "", True)
- __StartUp()
- While GUIGetMsg() <> -3
- $bitmap = ScreenToBitmap($screenDC, 10, 150, $GUI_W, $GUI_H)
- _GDIPlus_GraphicsClear($gfxContext, 0xFF555555)
- _GDIPlus_GraphicsDrawImage($gfxContext, $bitmap, 0, 0)
- ; _BitmapGetDiffPix($bitmap, $color)
- ; $bitmap to find different pixel
- ; $color to compare
- ; Return value
- ; $aDiffPix[n][0] = x
- ; $aDiffPix[n][1] = y
- ; $aDiffPix[n][2] = color
- $aDiffPix = _BitmapGetDiffPix($bitmap, 0xFFFFFFFF) ; 0xAARRGGBB
- For $i = 0 To UBound($aDiffPix) - 1
- _GDIPlus_PenSetColor($hPen, $aDiffPix[$i][2])
- _GDIPlus_GraphicsDrawEllipse($gfxContext, $aDiffPix[$i][0] - 10, $aDiffPix[$i][1] - 10, 20, 20, $hPen)
- Next
- _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
- WEnd
- Func _BitmapGetDiffPix($hBitmap, $Color)
- Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap) ;get width and height of the image
- 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 = 0x00000000 ;color format 0xAARRGGBB
- Local $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0)
- Local $iRowOffset, $tmparray[$iW * $iH][3], $index = 0, $pixel
- For $iY = 0 To $iH - 1
- $iRowOffset = $iY * $iW + 1
- For $iX = 0 To $iW - 1
- $pixel = DllStructGetData($tPixel, 1, $iRowOffset + $iX)
- If $pixel <> $Color Then
- $tmparray[$index][0] = $iX
- $tmparray[$index][1] = $iY
- $tmparray[$index][2] = $pixel
- $index += 1
- EndIf
- Next
- Next
- _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData) ;unlocks a portion of a bitmap that was locked by _GDIPlus_BitmapLockBits
- If $index = 0 Then Return False
- ReDim $tmparray[$index][3]
- Return $tmparray
- EndFunc ;==>Example
- Func ScreenToBitmap($hDC, $x, $y, $w, $h)
- Local $tDC = _WinAPI_CreateCompatibleDC($hDC)
- Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
- _WinAPI_SelectObject($tDC, $hBMP)
- _WinAPI_BitBlt($tDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)
- $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
- _WinAPI_DeleteObject($hBMP)
- _WinAPI_DeleteDC($tDC)
- ;~ Return $hBMP
- Return $hBitmap
- EndFunc
- Func __StartUp()
- $hDC = _WinAPI_GetDC($GUI)
- $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $GUI_W, $GUI_H)
- $buffer = _WinAPI_CreateCompatibleDC($hDC)
- _WinAPI_SelectObject($buffer, $hHBitmap)
- $gfxContext = _GDIPlus_GraphicsCreateFromHDC($buffer)
- _GDIPlus_GraphicsSetSmoothingMode($gfxContext, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
- _GDIPlus_GraphicsSetPixelOffsetMode($gfxContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
- $hPen = _GDIPlus_PenCreate(0)
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement