Jump to content

Displaying picture of screen, in GUI


bill88
 Share

Recommended Posts

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 by bill88
Link to comment
Share on other sites

#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

#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!

#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 by bill88
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...