bill88 Posted December 8, 2009 Share Posted December 8, 2009 (edited) Hello, I've written the following script: #include <ScreenCapture.au3> $GUI = freezeScreen() Sleep(10000) Func freezeScreen() Local $WS_POPUP = 0x80000000 ; ## Create Borderless GUI ## $GUI = GUICreate("Test", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) GUISetState(@SW_HIDE, $GUI) ; ## Save old coords of mouse, and move the mouse out of the way ## $oldCoords = MouseGetPos() MouseMove(@DesktopWidth, @DesktopHeight, 0) ; ## Take a picture of the screen, and move mouse back ## _ScreenCapture_Capture(@DesktopDir & "\tmp.jpg") ; Capture full screen MouseMove($oldCoords[0], $oldCoords[1], 0) ; ## Display picture, and show the GUI ## GUICtrlCreatePic(@DesktopDir & "\tmp.jpg", 0, 0, @DesktopWidth, @DesktopHeight) GUISetState(@SW_SHOW, $GUI) Return $GUI EndFunc It takes a picture of the screen, and displays it on a full screen GUI. The problem I am having is, when using "Au3Info.exe", the color of the pixel is off. For example, on my screen at 585, 284, the pixel color is 0x3A6EA5. And at the same coordinates on the GUI(And same spot in the picture), it is 0x4A6D80. Is there anyway to make the image file pixel colors, 100% accurate to the desktop? Thanks, Bill88 Edited December 8, 2009 by bill88 Link to comment Share on other sites More sharing options...
Authenticity Posted December 8, 2009 Share Posted December 8, 2009 expandcollapse popup#include <ScreenCapture.au3> $GUI = freezeScreen() Do Until GUIGetMsg() = -3 GUIDelete() Exit Func freezeScreen() Local $WS_POPUP = 0x80000000, $hGUI, $hBitmap, $hBmp, $hGraphics ; ## Create Borderless GUI ## $hGUI = GUICreate("Test", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) ConsoleWrite(Hex(PixelGetColor(585, 284)) & @CRLF) ; ## Take a picture of the screen ## $hBmp = _ScreenCapture_Capture("", 0, 0, -1, -1, False) _GDIPlus_Startup() $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) _WinAPI_DeleteObject($hBmp) GUISetState() _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) ConsoleWrite(Hex(BitAND(_GDIPlus_BitmapGetPixel($hBitmap, 585, 284), 0xFFFFFF)) & @CRLF) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() Return $hGUI EndFunc Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "uint*", 0) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, $aResult[4]) EndFunc ;==>_GDIPlus_BitmapGetPixel Link to comment Share on other sites More sharing options...
bill88 Posted December 8, 2009 Author Share Posted December 8, 2009 (edited) expandcollapse popup#include <ScreenCapture.au3> $GUI = freezeScreen() Do Until GUIGetMsg() = -3 GUIDelete() Exit Func freezeScreen() Local $WS_POPUP = 0x80000000, $hGUI, $hBitmap, $hBmp, $hGraphics ; ## Create Borderless GUI ## $hGUI = GUICreate("Test", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) ConsoleWrite(Hex(PixelGetColor(585, 284)) & @CRLF) ; ## Take a picture of the screen ## $hBmp = _ScreenCapture_Capture("", 0, 0, -1, -1, False) _GDIPlus_Startup() $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) _WinAPI_DeleteObject($hBmp) GUISetState() _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) ConsoleWrite(Hex(BitAND(_GDIPlus_BitmapGetPixel($hBitmap, 585, 284), 0xFFFFFF)) & @CRLF) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() Return $hGUI EndFunc Func _GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY) Local $aResult = DllCall($ghGDIPDll, "uint", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "uint*", 0) If @error Then Return SetError(@error, @extended, 0) Return SetError($aResult[0], 0, $aResult[4]) EndFunc ;==>_GDIPlus_BitmapGetPixel Thanks, the pixel color is the same now. Didn't realize there was an option to not include the mouse . Although I have 2 problems now. 1). Anything dragged across the GUI, will remove parts of the image. 2). The toolbar doesn't show up on the GUI, it's just gray. Edit: Fixed, thanks again! expandcollapse popup#include <ScreenCapture.au3> Global $hBmp Local $hGUI, $active = True $hGUI = freezeScreen() Do ; ## If window not active, then redraw ## If Not WinActive("Test") Then $active = False drawBitmap($hGUI, $hBmp) Sleep(50) EndIf ; ## If window is active, and it wasn't before, then redraw ## If WinActive("Test") And $active = False Then $active = True drawBitmap($hGUI, $hBmp) EndIf Until GUIGetMsg() = -3 _WinAPI_DeleteObject($hBmp) GUIDelete() Func freezeScreen() Local $WS_POPUP = 0x80000000, $hGUI ; ## Create Borderless GUI ## $hGUI = GUICreate("Test", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) ; ## Take a picture of the screen ## $hBmp = _ScreenCapture_Capture("", 0, 0, -1, -1, False) ; ## Show GUI, and draw bitmap ## GUISetState(@SW_SHOW, $hGUI) drawBitmap($hGUI, $hBmp) Return $hGUI EndFunc Func drawBitmap($hGUI, $hBmp) Local $hBitmap, $hGraphics ; ## ## _GDIPlus_Startup() $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp) _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) ; ## Release Rsources ## _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndFunc Edited December 8, 2009 by bill88 Link to comment Share on other sites More sharing options...
Authenticity Posted December 8, 2009 Share Posted December 8, 2009 If you want to restore the window background, you can handle the $GUI_EVENT_RESTORE and paint. Alternatively, once you get the bitmap handle ($hBmp not $hBitmap) you can use Icons.au3 by Yashied and use the _SetHImage() function, if you're not interested in a temporary image file. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now