Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.56 KB | None | 0 0
  1.  
  2. #include <GDIPlus.au3>
  3. #include <WinAPI.au3>
  4. #include <Memory.au3>
  5. #include <WindowsConstants.au3>
  6.  
  7. HotKeySet("{ESC}","_exit")
  8. Func _exit()
  9.     Exit
  10. EndFunc
  11.  
  12.  
  13. _GDIPlus_Startup()
  14. Global $screenDC
  15. Global $gfxContext, $hDC, $hHBitmap, $buffer, $hPen
  16. Global $GUI, $GUI_W = 400, $GUI_H = 400
  17.  
  18. ; chay notepad
  19. If ProcessExists("mspaint.exe") = False Then Run("mspaint.exe")
  20. $hwnd = WinWait("[CLASS:MSPaintApp]")
  21.  
  22. $screenDC = _WinAPI_GetDc($hwnd) ; neu muon chup man hinh thi cho $hwnd = 0
  23.  
  24. $GUI = GUICreate("", $GUI_W, $GUI_H)
  25. GUISetState()
  26. WinSetOnTop($GUI, "", True)
  27. __StartUp()
  28.  
  29. While GUIGetMsg() <> -3
  30.  
  31.     $bitmap = ScreenToBitmap($screenDC, 10, 150, $GUI_W, $GUI_H)
  32.  
  33.     _GDIPlus_GraphicsClear($gfxContext, 0xFF555555)
  34.     _GDIPlus_GraphicsDrawImage($gfxContext, $bitmap, 0, 0)
  35.  
  36.     ; _BitmapGetDiffPix($bitmap, $color)
  37.     ; $bitmap to find different pixel
  38.     ; $color to compare
  39.     ; Return value
  40.     ; $aDiffPix[n][0] = x
  41.     ; $aDiffPix[n][1] = y
  42.     ; $aDiffPix[n][2] = color
  43.  
  44.     $aDiffPix = _BitmapGetDiffPix($bitmap, 0xFFFFFFFF) ; 0xAARRGGBB
  45.  
  46.     For $i = 0 To UBound($aDiffPix) - 1
  47.         _GDIPlus_PenSetColor($hPen, $aDiffPix[$i][2])
  48.         _GDIPlus_GraphicsDrawEllipse($gfxContext, $aDiffPix[$i][0] - 10, $aDiffPix[$i][1] - 10, 20, 20, $hPen)
  49.     Next
  50.  
  51.     _WinAPI_BitBlt($hDC, 0, 0, $GUI_W, $GUI_H, $buffer, 0, 0, $SRCCOPY)
  52. WEnd
  53.  
  54. Func _BitmapGetDiffPix($hBitmap, $Color)
  55.  
  56.     Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap) ;get width and height of the image
  57.  
  58.     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
  59.     Local $iScan0 = DllStructGetData($tBitmapData, "Scan0") ;get scan0 (pixel data) from locked bitmap
  60.     Local $iSearchPixel = Int(0xFF000080), $iReplaceColor = 0x00000000 ;color format 0xAARRGGBB
  61.     Local $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0)
  62.     Local $iRowOffset, $tmparray[$iW * $iH][3], $index = 0, $pixel
  63.  
  64.     For $iY = 0 To $iH - 1
  65.         $iRowOffset = $iY * $iW + 1
  66.         For $iX = 0 To $iW - 1
  67.  
  68.             $pixel = DllStructGetData($tPixel, 1, $iRowOffset + $iX)
  69.             If $pixel <> $Color Then
  70.                 $tmparray[$index][0] = $iX
  71.                 $tmparray[$index][1] = $iY
  72.                 $tmparray[$index][2] = $pixel
  73.                 $index += 1
  74.             EndIf
  75.         Next
  76.     Next
  77.     _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData) ;unlocks a portion of a bitmap that was locked by _GDIPlus_BitmapLockBits
  78.     If $index = 0 Then Return False
  79.  
  80.     ReDim $tmparray[$index][3]
  81.     Return $tmparray
  82. EndFunc   ;==>Example
  83.  
  84.  
  85. Func ScreenToBitmap($hDC, $x, $y, $w, $h)
  86.  
  87.     Local $tDC = _WinAPI_CreateCompatibleDC($hDC)
  88.     Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
  89.     _WinAPI_SelectObject($tDC, $hBMP)
  90.     _WinAPI_BitBlt($tDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)
  91.  
  92.     $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
  93.  
  94.     _WinAPI_DeleteObject($hBMP)
  95.     _WinAPI_DeleteDC($tDC)
  96. ;~     Return $hBMP
  97.     Return $hBitmap
  98. EndFunc
  99.  
  100. Func __StartUp()
  101.  
  102.     $hDC = _WinAPI_GetDC($GUI)
  103.     $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $GUI_W, $GUI_H)
  104.  
  105.     $buffer = _WinAPI_CreateCompatibleDC($hDC)
  106.     _WinAPI_SelectObject($buffer, $hHBitmap)
  107.  
  108.     $gfxContext = _GDIPlus_GraphicsCreateFromHDC($buffer)
  109.     _GDIPlus_GraphicsSetSmoothingMode($gfxContext, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
  110.     _GDIPlus_GraphicsSetPixelOffsetMode($gfxContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
  111.     $hPen = _GDIPlus_PenCreate(0)
  112. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement