Sign in to follow this  
Followers 0
Totter

How to put _GDIPlus Bitmap to Clipboard?

2 posts in this topic

Hi 

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_Open(0)
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBitmap, $CF_BITMAP )
_ClipBoard_Close()

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>


_Example()


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


_ClipBoard_Open(0)
_ClipBoard_Empty()
$hBitmap1=_GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
;~ _WinAPI_CreateCompatibleBitmap($hBitmap1, 200,200)
_GDIPlus_BitmapDispose($hBitmap)
_ClipBoard_SetDataEx($hBitmap1, $CF_BITMAP )
_ClipBoard_Close()
_WinAPI_DeleteObject($hBitmap1)




_GDIPlus_Shutdown()


EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

Solved!

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)   
  _WinAPI_DeleteObject($hBitmap2)    
 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  
Followers 0