Jump to content

how to screen capture?


Recommended Posts

Quote

I wonder if it is possible to make the photo symmetrical

Yes,  just like this:

#include <GDIPlus.au3>

Local $iFname, $oFname, $tmptxt = ""

$iFname = FileOpenDialog("Open a file", @ScriptDir, "All (*.*)")
If StringRight(@ScriptDir, 1) <> "\" Then $tmptxt = "\"

$oFname = @ScriptDir & $tmptxt & "test.png"
_GDIPlus_BitmapAppendMirrorImage($iFname, $oFname)


Func _GDIPlus_BitmapAppendMirrorImage($fname, $outFname)
    ;Modified code from https://www.autoitscript.com/forum/topic/183062-solved-looking-for-method-to-append-images-moved/
    ;By Dan_555
    _GDIPlus_Startup()

    Local $i, $aDim, $iW = 0, $iH = 0, $aImage1, $aImage2, $iY = 0

    $aImage1 = _GDIPlus_ImageLoadFromFile($fname)
    $aDim = _GDIPlus_ImageGetDimension($aImage1)
    $iW = $aDim[0]
    $iH = $aDim[1]
    $aImage2 = _GDIPlus_ImageClone($aImage1)
    _GDIPlus_ImageRotateFlip($aImage2, 4)
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW * 2, $iH), $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    $aDim = _GDIPlus_ImageGetDimension($aImage1)

    _GDIPlus_GraphicsDrawImageRect($hGfx, $aImage1, 0, 0, $aDim[0], $aDim[1])
    _GDIPlus_GraphicsDrawImageRect($hGfx, $aImage2, $aDim[0], 0, $aDim[0], $aDim[1])

    _GDIPlus_ImageDispose($aImage1)
    _GDIPlus_ImageDispose($aImage2)

    _GDIPlus_GraphicsDispose($hGfx)

    _GDIPlus_ImageSaveToFile($hBitmap, $outFname)
    _GDIPlus_ImageDispose($hBitmap)

    _GDIPlus_Shutdown()

    $aDim=""
EndFunc   ;==>_GDIPlus_BitmapAppendMirrorImage

i had to modify the code from this post:

 

Quote

or adjust the transparency with Auto-It. 

I do not know how to do that atm.

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Dan_555, the code you modified is really great. 

The method of simultaneously storing two images of the mirror image you selected is excellent. 

However, I would like to be able to save a single change image. 

For example, I want to know how to save the two images as test.png and the replaced image as test2.png.

 

Link to comment
Share on other sites

Quote

However, I would like to be able to save a single change image. 

I took few lines from my last post, and here it is, now saving single mirrored image: 

#include <GDIPlus.au3>

Local $iFname, $oFname, $tmptxt = ""

$iFname = FileOpenDialog("Open a file", @ScriptDir, "All (*.*)")
If StringRight(@ScriptDir, 1) <> "\" Then $tmptxt = "\"

$oFname = @ScriptDir & $tmptxt & "test.png"
_GDIPlus_BitmapMirrorImage($iFname, $oFname)


Func _GDIPlus_BitmapMirrorImage($fname, $outFname)
    ;Modified code from https://www.autoitscript.com/forum/topic/183062-solved-looking-for-method-to-append-images-moved/
    ;By Dan_555
    _GDIPlus_Startup()

    Local $i, $aDim, $iW = 0, $iH = 0, $aImage1, $iY = 0

    $aImage1 = _GDIPlus_ImageLoadFromFile($fname)           ;Load an image
    $aDim = _GDIPlus_ImageGetDimension($aImage1)            ;Read the dimensions of the image and put it into the $aDim array
    $iW = $aDim[0]          ;Width
    $iH = $aDim[1]          ;Height

    _GDIPlus_ImageRotateFlip($aImage1, 4)       ;Perform image rotation on the loaded image
    
    Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)         ;Create a buffer $hBitmap with the dimensions of the loaded image.
    Local $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap)

    _GDIPlus_GraphicsDrawImageRect($hGfx, $aImage1, 0, 0, $aDim[0], $aDim[1])   ;Draw the loaded image on the buffer 

    _GDIPlus_ImageDispose($aImage1)                     ;Free the image

    _GDIPlus_GraphicsDispose($hGfx)                     ;Free graphic

    _GDIPlus_ImageSaveToFile($hBitmap, $outFname)       ;Save the buffer
    _GDIPlus_ImageDispose($hBitmap)                     ;Free the bitmap

    _GDIPlus_Shutdown()

    $aDim=""
EndFunc   ;==>_GDIPlus_BitmapAppendMirrorImage
Quote

For example, I want to know how to save the two images as test.png and the replaced image as test2.png.

I have no idea what you are trying to do, or why do you need that many copies of the pictures.

But with the last 2 code samples, you have enough information to save whatever images you like to have.

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Dan_555, how are you, 

I entered the code you provided and got a satisfactory result. 

I really appreciate it. But now I want to touch the part of the capture code. 

I am wondering if there is a way to capture the part corresponding to the picture control area. 

For example, if the form moves, the capture control moves as well, and I am wondering if I can only capture the stopped picture control part. 

Currently, my capture method is a method of capturing only selected parts. 

My code is below.

Func Screen_Capture()

 _GDIPlus_Startup()
 $hBitmap2 = _ScreenCapture_Capture("", 100, 100, 300, 300, False) ; 200 x 200
 ;$hBitmap2 = _ScreenCapture_Capture("", 100, 100, 400, 400,True) ; 200 x 200
 $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap2)
 $hImage = _GDIPlus_ImageResize($hImage2, 300, 300) ; resize to 300 x 300
 $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

 _SetBitmapToCtrl($Pic, $hBitmap)

 ;Clean up and shutdown GDIPlus.
 _GDIPlus_ImageDispose($hImage)
 _GDIPlus_ImageDispose($hImage2)
 _WinAPI_DeleteObject($hBitmap)
 _WinAPI_DeleteObject($hBitmap2)
 _GDIPlus_Shutdown()

EndFunc

Func _SetBitmapToCtrl($CtrlId, $hBitmap)
  Local Const $SS_IMAGE_BITMAP = 0

  Local $hWnd = GUICtrlGetHandle($CtrlId)
  If $hWnd = 0 Then Return SetError(1, 0, 0)

  _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
  If @error Then Return SetError(4, 0, 0)
  Return 1

EndFunc   ;==>_SetBitmapToCtrl

 

Link to comment
Share on other sites

@halbum2040  If you are to set Bitmap to Ctrl multiple times, you need to delete old objects otherwise you will face a massive memory leak.  I am talking from experience here ;)

Use something like this :

Local $hPrev  = _SendMessage($hWnd, $STM_SETIMAGE, $SS_IMAGE_BITMAP, $hBitmap)
If @error Then Return SetError(1, 0, 0)
If $hPrev Then _WinAPI_DeleteObject($hPrev)

It is a good practice to have this function modified anyway...

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...