Ahbadiane Posted November 8, 2010 Share Posted November 8, 2010 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 ) 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 Link to comment Share on other sites More sharing options...
Kyme Posted November 8, 2010 Share Posted November 8, 2010 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 ) 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 Link to comment Share on other sites More sharing options...
Yashied Posted November 8, 2010 Share Posted November 8, 2010 _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile($sImage) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Ahbadiane Posted November 8, 2010 Author Share Posted November 8, 2010 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() Link to comment Share on other sites More sharing options...
UEZ Posted November 8, 2010 Share Posted November 8, 2010 (edited) Try this:expandcollapse popup#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_CopyIconBr,UEZ Edited November 8, 2010 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Ahbadiane Posted November 8, 2010 Author Share Posted November 8, 2010 UEZ, I finally have a solution to my problem A big thank you Ahbadiane Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now