Sign in to follow this  
Followers 0
Ahbadiane

JPG to Clipboard

6 posts in this topic

Hello,

I want to put an image (jpg) to the clipboard

My first tests give me a black image :( in the clipbaord (but with the right size :graduated:)

Here is the code

#include <ClipBoard.au3>
#include <GDIPlus.au3>

Global $sImageName = @ScriptDir & "\Image1.jpg"

_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sImageName) ; => Handle to the image object
Global $hBmp = _WinAPI_CreateBitmap(_GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage), 1, 32) ; The handle to a bitmap
_ClipBoard_Open("")
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBmp, $CF_BITMAP)
_ClipBoard_Close()
_GDIPlus_Shutdown()

Ahbadiane

Share this post


Link to post
Share on other sites



Hello,

I want to put an image (jpg) to the clipboard

My first tests give me a black image :( in the clipbaord (but with the right size :graduated:)

Here is the code

#include <ClipBoard.au3>
#include <GDIPlus.au3>

Global $sImageName = @ScriptDir & "\Image1.jpg"

_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sImageName) ; => Handle to the image object
Global $hBmp = _WinAPI_CreateBitmap(_GDIPlus_ImageGetWidth($hImage), _GDIPlus_ImageGetHeight($hImage), 1, 32) ; The handle to a bitmap
_ClipBoard_Open("")
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBmp, $CF_BITMAP)
_ClipBoard_Close()
_GDIPlus_Shutdown()

Ahbadiane

maybe _ClipBoard_SetDataEx and _ClipBoard_GetDataEx will help you an little

Regards

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Kyme

I do well to call _ClipBoard_SetDataEx ($ hBmp, $ CF_BITMAP), but perhaps not with the proper Handle

Yashied,

The following code does not produce images at all!

#include <ClipBoard.au3>
#include <GDIPlus.au3>
Global $sImageName = @ScriptDir & "\Image1.jpg"
_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sImageName)
Global $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
_ClipBoard_Open("")
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
_ClipBoard_Close()
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try this:

#include <ClipBoard.au3>
#include <Constants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>

Global $sImageName = FileOpenDialog("Select an image", "", "Image (*.bmp;*.jpg;*.png;*.gif)")
If @error Then Exit

_GDIPlus_Startup ()
$hImage = _GDIPlus_ImageLoadFromFile($sImageName)
$hBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hBitmap = _WinAPI_CopyImage($hBmp, 0, 0, 0, $LR_COPYDELETEORG + $LR_COPYRETURNORG)

_ClipBoard_Open(0)
_ClipBoard_Empty()
_ClipBoard_SetDataEx($hBitmap, $CF_BITMAP)
_ClipBoard_Close()
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()

MsgBox(0, "Copy to Clipboard", "Successfully bitmap copied to clipboard!", 10)


;===============================================================================
;
; Function Name:   _WinAPI_CopyImage
; Description:: Copies an image, also makes GDIPlus-HBITMAP to GDI32-BITMAP
; Parameter(s): $hImg -> HBITMAP Object, GDI or GDIPlus
; Requirement(s):  WinAPI.au3
; Return Value(s): Succes: Handle to new Bitmap, Error: 0
; Author(s):    Prog@ndy
; http://www.autoitscript.com/forum/topic/70237-images-and-the-clipboard/page__p__514857
;===============================================================================
Func _WinAPI_CopyImage($hImg, $uType = 0 ,$x = 0, $y = 0, $flags = 0)
    Local $aResult

    $aResult = DllCall("User32.dll", "hwnd", "CopyImage", "hwnd", $hImg, "UINT", $uType, "int", $x, "int", $y,"UINT", $flags)
;~  _WinAPI_Check("_WinAPI_CopyImage", ($aResult[0] = 0), 0, True)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_CopyIcon

Br,

UEZ

Edited by UEZ

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!
¯\_(ツ)_/¯

Share this post


Link to post
Share on other sites

UEZ, :graduated:

I finally have a solution to my problem

A big thank you

Ahbadiane

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