Jump to content
Sign in to follow this  
confucion

Enlarge/Zoom image after screencapture?

Recommended Posts

confucion

After a screencapture:

#include <Clipboard.au3>
#include <ScreenCapture.au3>

$hHBITMAP = _ScreenCapture_Capture("", 0, 0, 100, 100)
_ClipBoard_SetDataEx($hHBITMAP, $CF_BITMAP)

How do I enlarge/zoom it before putting it into the clipboard?

Share this post


Link to post
Share on other sites
smashly

Hi,

Can't help with the Clipboard side of things as I don't feel like learning the functions and how they work.

(Clipboard function _ClipBoard_SetDataEx returns 0x000000 with your code, so I didn't bother with the clipboard part)

But hopefully this may give you insight into enlarging your screen capture, just adapt it to your needs.

#include <GDIPlus.au3>
#include <ScreenCapture.au3>

$hHBITMAP = _ScreenCapture_Capture("", 0, 0, 100, 100)

_GDIPlus_Startup()

; Create a Bitmap object from the bitmap handle
$hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hHBITMAP)

; Dispose of the original capture since we now have a bitmap image we can use with GDIPlus.
_WinAPI_DeleteObject($hHBITMAP)

; Get the graphics context of the bitmap image.
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage)

; Creates a new Bitmap object based on the Graphic object with a new width and height.
$hHBITMAP = _GDIPlus_BitmapCreateFromGraphics(200, 200, $hGraphic)

; Dispose of the Graphic context now we have a newly sized bitmap image as a canvas.
_GDIPlus_GraphicsDispose($hGraphic)

; Get the graphics context of the newly sized bitmap image
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hHBITMAP)

; Draw the original image onto the newly sized image.
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 200, 200)

; Dispose of the Graphic context now we have drawn the original image to it.
_GDIPlus_GraphicsDispose($hGraphic)

; Saving to see what the newly sized image is like.
_GDIPlus_ImageSaveToFile($hHBITMAP, @ScriptDir & "\200x200.jpg")

; Dispose of the original image.
_GDIPlus_ImageDispose($hImage)

; Dispose of the new resized bitmap.
_WinAPI_DeleteObject($hHBITMAP)

_GDIPlus_ShutDown ()

ShellExecute(@ScriptDir & "\200x200.jpg")

Cheers

Share this post


Link to post
Share on other sites
confucion

Here is working code by UEZ from another post that has the screencapture to clipboard working. I tried implementing your resize image code but can't seem to get both code working together. Your code to resize, saving the image to file and viewing it works fine but I can't get the resized image to save to the clipboard and then paste back into MSPAINT.EXE from the clipboard. Can you give it a try? Thank you.

;code by UEZ
#include <Clipboard.au3>
#include <ScreenCapture.au3>
$err = False
$hHBITMAP = _ScreenCapture_Capture("", 0, 0, 100, 100)
If Not _ClipBoard_Open(0) Then
    $err = @error
    $err_txt = "_ClipBoard_Open failed!"
EndIf
If Not _ClipBoard_Empty() Then
    $err = @error
    $err_txt = "_ClipBoard_Empty failed!"
EndIf
If Not _ClipBoard_SetDataEx($hHBITMAP, $CF_BITMAP) Then
    $err = @error
    $err_txt = "_ClipBoard_SetDataEx failed!"
EndIf
_ClipBoard_Close()
_WinAPI_DeleteObject($hHBITMAP)
If Not $err Then
    MsgBox(0, "Information", "Image put to clipboard!", 10)
Else
    MsgBox(0, "Error", "An error has occured: " & $err_txt, 10)
EndIf
Exit

Share this post


Link to post
Share on other sites
smashly

Hi,

Something like this

#include <GDIPlus.au3>
#include <Clipboard.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>

$iNewWidth = 200
$iNewHeight = 200

$err = False
$hHBITMAP = _ScreenCapture_Capture("", 0, 0, 100, 100)

_GDIPlus_Startup()
$hImage = _GDIPlus_BitmapCreateFromHBITMAP ($hHBITMAP)
_WinAPI_DeleteObject($hHBITMAP)
$hHBITMAP = _WinAPI_CreateBitmap($iNewWidth, $iNewHeight, 1, 32)
$hCDC = _WinAPI_CreateCompatibleDC(0)
_WinAPI_SelectObject($hCDC, $hHBITMAP)
$hGraphic = _GDIPlus_GraphicsCreateFromHDC($hCDC)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iNewWidth, $iNewHeight)
_WinAPI_DeleteObject($hImage)
_GDIPlus_GraphicsDispose($hGraphic)
_WinAPI_DeleteDC($hCDC)
_GDIPlus_Shutdown()

If Not _ClipBoard_Open(0) Then
    $err = @error
    $err_txt = "_ClipBoard_Open failed!"
EndIf
If Not _ClipBoard_Empty() Then
    $err = @error
    $err_txt = "_ClipBoard_Empty failed!"
EndIf
If Not _ClipBoard_SetDataEx($hHBITMAP, $CF_BITMAP) Then
    $err = @error
    $err_txt = "_ClipBoard_SetDataEx failed!"
EndIf
_ClipBoard_Close()
_WinAPI_DeleteObject($hHBITMAP)
If Not $err Then
    MsgBox(0, "Information", "Image put to clipboard!", 10)
Else
    MsgBox(0, "Error", "An error has occured: " & $err_txt, 10)
EndIf

Cheers

Edited by smashly
  • Like 1

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.