Jump to content

Capturing image without saving


 Share

Recommended Posts

I would like to get a region of the screen but avoiding having to save to a file first.
I believe it is a lack of knowledge on my part but the GUICtrlSetImage function does not allow you to define an image without being a file.
How to do this:

;....
$Pic3 = GUICtrlCreatePic("", 8, 64, 84, 84, -1, _
        $WS_EX_STATICEDGE) ;para ter borda em baixo relevo
;....

_ScreenCapture_Capture(@ScriptDir & "\areatemp.jpg", 10, 10, 200, 200)
GUICtrlSetImage($Pic3, @ScriptDir & "\areatemp.jpg")
;....

 

Link to comment
Share on other sites

If you use 

_ScreenCapture_Capture

Without a file argument it will return a handle to a bitmap image.

I see that 

_GDIPlus_GraphicsDrawImage

Will draw an image object from a handle to a bitmap image.

I've not tried any of that, and perhaps there is a much nicer way to do it, but until someone tells us.... :-)

 

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Link to comment
Share on other sites

yes I know that if I use the capture it returns me a handle of bitmapH but how to put it in a CreatePic.
I would like to better understand the function of creating a CreatePic instead of using the DrawImage ...
It would be lighter but if it does not have geito we will have to use the draw

If someone has a simpres and immediate suggestion it would be wonderful

Link to comment
Share on other sites

Here is a modified version of the _GDIPlus_GraphicsDrawImageRectRect() function's example in the AutoIt help file.

#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

Example()

Func Example()
    _GDIPlus_Startup() ;initialize GDI+
    Local Const $iWidth = 600, $iHeight = 600

    Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    Local $pIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object

    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iWidth, $iHeight) ;create a GDI bitmap by capturing an area on desktop
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    ; or
    ;_GDIPlus_GraphicsDrawImageRectRect($hGraphics, $hBitmap, 0, 0, $iWidth, $iHeight, 0, 0, $iWidth*2, $iHeight*2); Magnify use in destination  "$iWidth*2, $iHeight*2)"
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ;cleanup GDI+ resources
    _GDIPlus_ImageAttributesDispose($pIA)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Here is an easier one.

;#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
; Modified from https://www.autoitscript.com/forum/topic/131438-how-to-set-a-bitmap-into-a-pic-control-using-a-bitmap-handle/?do=findComment&comment=915168

Local $width = 100, $height = 100
;_GDIPlus_Startup()
Local $hGUI = GUICreate("Test", 320, 256)
Local $idPic = GUICtrlCreatePic("", 50, 50, $width, $height)
Local $hBmp = _ScreenCapture_Capture("", 100, 100, $width + 100, $height + 100) ; Create_Bitmap(100, 100)
Local $STM_SETIMAGE = 0x0172
GUICtrlSendMsg($idPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBmp)
_WinAPI_DeleteObject($hBmp)
;_GDIPlus_Shutdown()

GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3 ; $GUI_EVENT_CLOSE = -3
            ExitLoop
        Case $idPic
            MsgBox(0, "Test", "Picture was clicked!")
    EndSwitch
WEnd

 

Edited by Malkey
There are no GDIPlus functions used, so don't need GDIPlus include file, Startup, or, Shutdown functions.
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

×
×
  • Create New...