notsure Posted September 9, 2010 Share Posted September 9, 2010 (edited) Hello,I'm trying to save an Image to a file from the clipboard. This might sound a little odd but the only way to get the image is by copying it to the clipboard and then i want autoit to save it to a JPG file. Is there any way to achieve this? In the helpfile the only feature which comes close to what i want is "_ClipPut" but thats only to put files from the harddisk to the clipboard. I want it the other way around, so i save a file to the HDD from the clipboard.Any suggestions? Would be appreciated.Edit:I'm trying to do it this way:$hImage = _ClipBoard_GetData($CF_BITMAP) ; Initialize GDI+ library _GDIPlus_Startup () ; Capture full screen $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hImage) _GDIPlus_ImageSaveToFile ($hImage1, "C:\GDIPlus_Image.jpg") ; Shut down GDI+ library _GDIPlus_ShutDown ()But it isn't working, I don't get a file at all. Edited September 9, 2010 by notsure Link to comment Share on other sites More sharing options...
LurchMan Posted September 9, 2010 Share Posted September 9, 2010 Hello, I'm trying to save an Image to a file from the clipboard. This might sound a little odd but the only way to get the image is by copying it to the clipboard and then i want autoit to save it to a JPG file. Is there any way to achieve this? In the helpfile the only feature which comes close to what i want is "_ClipPut" but thats only to put files from the harddisk to the clipboard. I want it the other way around, so i save a file to the HDD from the clipboard. Any suggestions? Would be appreciated. Edit: I'm trying to do it this way: $hImage = _ClipBoard_GetData($CF_BITMAP) ; Initialize GDI+ library _GDIPlus_Startup () ; Capture full screen $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hImage) _GDIPlus_ImageSaveToFile ($hImage1, "C:\GDIPlus_Image.jpg") ; Shut down GDI+ library _GDIPlus_ShutDown () But it isn't working, I don't get a file at all. Why not just use: _ScreenCapture_Capture () This will take a screenshot and save it to a jpg..look for it in the help file. Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end. Link to comment Share on other sites More sharing options...
notsure Posted September 9, 2010 Author Share Posted September 9, 2010 Why not just use: _ScreenCapture_Capture () This will take a screenshot and save it to a jpg..look for it in the help file. Because of this. Link to comment Share on other sites More sharing options...
KaFu Posted September 9, 2010 Share Posted September 9, 2010 Interesting question .... #include <ClipBoard.au3> #include <GDIPlus.au3> If Not _ClipBoard_Open(WinGetHandle(AutoItWinGetTitle())) Then MsgBox(0, "", "_ClipBoard_Open failed") $hClipboardImage = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hClipboardImage) $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") _GDIPlus_ImageSaveToFileEx($hBitmap, @ScriptDir & "\" & TimerInit() & "_Clipboard_Image.jpg", $sCLSID, 0) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
notsure Posted September 9, 2010 Author Share Posted September 9, 2010 Fuck Yea! I owe you 1. Very nice KAFU, thx alot! Link to comment Share on other sites More sharing options...
KaFu Posted September 9, 2010 Share Posted September 9, 2010 (edited) You're welcome , here's a little check added: #include <ClipBoard.au3> #include <GDIPlus.au3> If _ClipBoard_IsFormatAvailable($CF_BITMAP) Then ConsoleWrite("+Bitmap found on Clipboard" & @CRLF) If Not _ClipBoard_Open(0) Then MsgBox(16, "Error", "_ClipBoard_Open failed") Exit EndIf $hClipboardImage = _ClipBoard_GetDataEx($CF_BITMAP) _ClipBoard_Close() _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hClipboardImage) $sCLSID = _GDIPlus_EncodersGetCLSID("JPG") _GDIPlus_ImageSaveToFileEx($hBitmap, @ScriptDir & "\" & TimerInit() & "_Clipboard_Image.jpg", $sCLSID, 0) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndIf Edited September 9, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
YellowLab Posted September 25, 2010 Share Posted September 25, 2010 (edited) Here is another way to do this: First you capture the window, this will work on hidden windows, but you will loose transparency: http://www.autoitscript.com/forum/index.php?showtopic=108822&view=findpost&p=834359 Func _CaptureWindow($hWnd) Local $WM_PAINT = 0x000F Local $WM_PRINT = 0x317 Local $PRF_CHILDREN = 0x10; Draw all visible child windows. Local $PRF_CLIENT = 0x4 ; Draw the window's client area. Local $PRF_OWNED = 0x20 ; Draw all owned windows. Local $PRF_NONCLIENT = 0x2 ; Draw the window's Title area. Local $PRF_ERASEBKGND = 0x8 ; Erases the background before drawing the window Local $pos = WinGetPos($hWnd) Local $Width = $pos[2] Local $Height = $pos[3] Local $hDC = _WinAPI_GetDC($hWnd) Local $memDC = _WinAPI_CreateCompatibleDC($hDC) Local $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height) _WinAPI_SelectObject ($memDC, $memBmp) Local $Ret = _SendMessage($hWnd, $WM_PAINT, $memDC, 0) $Ret = _SendMessage($hWnd, $WM_PRINT, $memDC, BitOR($PRF_CHILDREN , $PRF_CLIENT, $PRF_OWNED, $PRF_NONCLIENT, $PRF_ERASEBKGND)) Local $hBMP=_GDIPlus_BitmapCreateFromHBITMAP($memBmp) Local $hHBITMAP=_GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP) _WinAPI_DeleteObject($hDC) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject ($memBmp) _WinAPI_DeleteDC($hDC) Return $hHBITMAP EndFunc ;==>_CaptureWindow() Then you can use these functions to apply transparency back to the image: http://www.autoitscript.com/forum/index.php?showtopic=106797&view=findpost&p=753680 Local $hBITMAP=_GDIPlus_BitmapCreateFromHBITMAP(_CaptureWindow(WinGetHandle('YOUR WINDOW'))) ;looses transparency Local $hBMP=_ImageColorToTransparent($hBitmap,0xABCDEF) Local $hHBITMAP=_GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP) The capturewindow code could be modified to return a bitmap rather than an hbitmap since it is a double conversion - but my script needs the hbitmap multiple times and the bmp only once. The original solution doesn't work in some instances on Win7 x64 - at least for my script. My solution does work on that OS. Edited September 25, 2010 by YellowLab You can't see a rainbow without first experiencing the rain. Link to comment Share on other sites More sharing options...
Pottery Posted September 26, 2010 Share Posted September 26, 2010 Because of this.There's also _ScreenCapture_Wnd() that would fix the problem from that link 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