Jump to content
Sign in to follow this  

How to put _GDIPlus Bitmap to Clipboard?

Recommended Posts



I am trying to put GDIPlus bitmap to clipboard.

When I want to put Clipboard content to e.g. MS paint i have got Cannot paste or Not picture data in Gimp - error.

I am using this code to handle clipboard:

_ClipBoard_SetDataEx($hBitmap, $CF_BITMAP )

It works for GDI (HBITMAP - bitmap created without GDIPlus library e.g. with _ScreenCapture_Capture)


It not wors after converting it with _GDIPlus_BitmapCreateFromHBITMAP

I tried to convert it back with  

_GDIPlus_BitmapCreateHBITMAPFromBitmap and/or _WinAPI_CreateCompatibleBitmap

with no succes.

This is my code (only cut example from original code - i need to handle with _GDIPlus object):

#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#Include <ScreenCapture.au3>
#Include <Misc.au3>
#include <GDIPlus.au3>
#include <Clipboard.au3>


Func _Example()
    _GDIPlus_Startup() ;initialize GDI+

Local $hHBmp = _ScreenCapture_Capture("", 100, 100, 300,300) ;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

;~ _WinAPI_CreateCompatibleBitmap($hBitmap1, 200,200)
_ClipBoard_SetDataEx($hBitmap1, $CF_BITMAP )


EndFunc   ;==>Example


Share this post

Link to post
Share on other sites


I used  this:

('?do=embed' frameborder='0' data-embedContent>>:

;=============================================================================== ;
; Function Name:   _GDIPlus_ImageCreateGDICompatibleHBITMAP
; Description::    Converts a GDIPlus-Image to GDI-combatible HBITMAP 
; Parameter(s):    $hImg -> GDIplus Image object ; Requirement(s):  GDIPlus.au3
; Return Value(s): HBITMAP, compatible with ClipBoard 
; Author(s):       Prog@ndy ;
; Func _GDIPlus_ImageCreateGDICompatibleHBITMAP($hImg)
  Local $hBitmap2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImg)     
  Local $hBitmap = _WinAPI_CopyImage($hBitmap2,0,0,0,$LR_COPYDELETEORG+$LR_COPYRETURNORG)   
 Return $hBitmap EndFunc

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