Jump to content

Save clipboard image to jpg file


Recommended Posts

Hi,

Been searching around the forums and found a couple of snippets that other's claim works, but it doesn't seem to be working for me. I'm basically wanting to be able to copy and image to clipboard, or via the snipping tool in Windows 7 and then click a button that saves this to a file so I could do some further processing with it. Here is what I have.\

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

#include <ScreenCapture.au3>

_Main()

Func _Main()
    Local $hBmp

    ; Capture full screen
    $hBmp = _ClipBoard_GetDataEx ($CF_BITMAP )

    ; Save bitmap to file
    _ScreenCapture_SaveImage (@MyDocumentsDir & "\Image.jpg", $hBmp)

EndFunc   ;==>_Main

Can someone please point me in the right direction.

Thanks,

Max

Link to comment
Share on other sites

Help-File example is close...CTRL+ALT+s to save screenshot...

#include <ScreenCapture.au3>

HotKeySet("{ESC}", "_Exit")
HotKeySet("^!s", "_Screenshot")

While 1
    Sleep(10)
WEnd

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Screenshot()
    Local $hBmp
    $hBmp = _ScreenCapture_Capture("")
    $file = FileSaveDialog("Save Screenshot", @ScriptDir, "jpg (*.jpg)", 18, "screenshot.jpg")
    If Not @error Then _ScreenCapture_SaveImage($file, $hBmp)
EndFunc   ;==>_Screenshot
Link to comment
Share on other sites

Max Kipness

Your example appears to be trying to combine these two methods.

#include <ScreenCapture.au3>

_ScreenCapture_Capture(@ScriptDir & "\GDIPlus_Image.jpg")
ShellExecute(@ScriptDir & "\GDIPlus_Image.jpg")
and

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

; Capture full screen
Send("{PRINTSCREEN}") ; Screen
;Send("!{PRINTSCREEN}") ; window

_Main()

ShellExecute(@ScriptDir & "\Image.jpg")

Func _Main()
    Local $hBmp, $hImage

    If Not _ClipBoard_Open(0) Then _WinAPI_ShowError("_ClipBoard_Open failed")
    $hBmp = _ClipBoard_GetDataEx($CF_BITMAP)
    _GDIPlus_Startup()
    $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)

    ; Save bitmap to file
    _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\Image.jpg") ;$sNewName)

    _GDIPlus_BitmapDispose($hImage)
    _GDIPlus_Shutdown()
    _ClipBoard_Close()

EndFunc ;==>_Main
Edited by Malkey
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...