Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 3.16 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)
  57.  
  58.     Local $tBitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iW, $iH, BitOR($GDIP_ILMWRITE, $GDIP_ILMREAD), $GDIP_PXF32ARGB)
  59.     Local $iScan0 = DllStructGetData($tBitmapData, "Scan0")
  60.     Local $tPixel = DllStructCreate("int[" & $iW * $iH & "];", $iScan0)
  61.     Local $iRowOffset, $tmparray[$iW * $iH][3], $index = 0, $pixel
  62.  
  63.     For $iY = 0 To $iH - 1
  64.         $iRowOffset = $iY * $iW + 1
  65.         For $iX = 0 To $iW - 1
  66.  
  67.             $pixel = DllStructGetData($tPixel, 1, $iRowOffset + $iX)
  68.             If $pixel <> $Color Then
  69.                 $tmparray[$index][0] = $iX
  70.                 $tmparray[$index][1] = $iY
  71.                 $tmparray[$index][2] = $pixel
  72.                 $index += 1
  73.             EndIf
  74.         Next
  75.     Next
  76.     _GDIPlus_BitmapUnlockBits($hBitmap, $tBitmapData)
  77.     If $index = 0 Then Return False
  78.  
  79.     ReDim $tmparray[$index][3]
  80.     Return $tmparray
  81. EndFunc
  82.  
  83.  
  84. Func ScreenToBitmap($hDC, $x, $y, $w, $h)
  85.  
  86.     Local $tDC = _WinAPI_CreateCompatibleDC($hDC)
  87.     Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h)
  88.     _WinAPI_SelectObject($tDC, $hBMP)
  89.     _WinAPI_BitBlt($tDC, 0, 0, $w, $h, $hDC, $x, $y, $SRCCOPY)
  90.  
  91.     $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
  92.  
  93.     _WinAPI_DeleteObject($hBMP)
  94.     _WinAPI_DeleteDC($tDC)
  95. ;~     Return $hBMP
  96.     Return $hBitmap
  97. EndFunc
  98.  
  99. Func __StartUp()
  100.  
  101.     $hDC = _WinAPI_GetDC($GUI)
  102.     $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $GUI_W, $GUI_H)
  103.  
  104.     $buffer = _WinAPI_CreateCompatibleDC($hDC)
  105.     _WinAPI_SelectObject($buffer, $hHBitmap)
  106.  
  107.     $gfxContext = _GDIPlus_GraphicsCreateFromHDC($buffer)
  108.     _GDIPlus_GraphicsSetSmoothingMode($gfxContext, $GDIP_SMOOTHINGMODE_HIGHQUALITY)
  109.     _GDIPlus_GraphicsSetPixelOffsetMode($gfxContext, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
  110.     $hPen = _GDIPlus_PenCreate(0)
  111. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement