Jump to content

How to put image on clipboard using _ClipBoard_SetData


Go to solution Solved by UEZ,

Recommended Posts

_ScreenCapture_CaptureWnd ( $g_SnapShotDirectory & "\" & $g_sSnapShotName & "_Edited.jpg", $g_SnapShotWindow, 0 , 0, -1, -1, False ) ; Save a copy to disk
_GDIPlus_Startup()
Local $hImg = _GDIPlus_ImageLoadFromFile($g_SnapShotDirectory & "\" & $g_sSnapShotName & "_Edited.jpg")
Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg)
_GDIPlus_ImageDispose($hImg)
_GDIPlus_Shutdown()
_ClipBoard_SetData($hBitmap)

Repro Steps:

- Capture screenshot of window, save to disk

- Load image from disk

- Convert it into a HBITMAP

- Place the image on the clipboard

Results:

- Nothing getting on the clipboard (pasting into mspaint not working)

Expected:

- Image is placed on clipboard so I can paste it into other apps.

I'm missing something because many other people have done this and this code is pretty much copy/paste out of other forum posts. What am I doing wrong? I tried adding $CF_BITMAP for the iFormat param but nothing changed.

Link to comment
Share on other sites

  • Solution

You have to use 

_WinAPI_CopyImage
_ClipBoard_SetDataEx

to put a GDI image to the clipboard.

Not tested example

$hHBitmap = _ScreenCapture_CaptureWnd ("", $g_SnapShotWindow, 0 , 0, -1, -1, False )
$hClipboard_Bitmap = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
_WinAPI_DeleteObject($hHBitmap)
_ClipBoard_Open(0)
$hCP = _ClipBoard_SetDataEx($hClipboard_Bitmap, $CF_BITMAP)
_ClipBoard_Close()

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

 

You have to use 

_WinAPI_CopyImage
_ClipBoard_SetDataEx

to put a GDI image to the clipboard.

Not tested example

$hHBitmap = _ScreenCapture_CaptureWnd ("", $g_SnapShotWindow, 0 , 0, -1, -1, False )
$hClipboard_Bitmap = _WinAPI_CopyImage($hHBitmap, 0, 0, 0, BitOR($LR_COPYDELETEORG, $LR_COPYRETURNORG))
_WinAPI_DeleteObject($hHBitmap)
_ClipBoard_Open(0)
$hCP = _ClipBoard_SetDataEx($hClipboard_Bitmap, $CF_BITMAP)
_ClipBoard_Close()

 

That did the trick! Thank you!

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