Jump to content

Save image in clipboard to file...


 Share

Recommended Posts

I am so lost on this that I don't actually know where to start, so I do not have any code at this time.
I want to be able to save an image captured through PrtScn to a file. Obviously, I need to automate that task.

If anyone could figure this out and perhaps turn it into a function (If you do not wish to make a function out of it, I understand. That part I can do on my own anyway.), you would make my day. I have never actually been to a point where I was this kind of lost before, so please bare with me.

Thank you all for your time.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Something like this here?

#include <GDIPlus.au3>
#include <Clipboard.au3>

_GDIPlus_Startup()
Global $hMemoryBMP = 0, $hBmp, $hWnd = WinGetHandle(AutoItWinGetTitle())
HotKeySet("+!q", "_Exit") ;Shift+Alt+q to exit

_ClipBoard_Open($hWnd)
_ClipBoard_Empty()
_ClipBoard_Close()
Sleep(100)

Do
    If Not _ClipBoard_Open($hWnd) Then
        ConsoleWrite("Could not open clipboard!!!" & @CRLF)
        _Exit()
    EndIf
    $hMemoryBMP = _ClipBoard_GetDataEx($CF_BITMAP)
    If $hMemoryBMP Then
        $sFile = FileSaveDialog("Save Bitmap from Clipboard", "", "Images(*.jpg;*.bmp;*.png;*.gif)")
        If @error Then ContinueLoop
        $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hMemoryBMP)
        If _GDIPlus_ImageSaveToFile($hBmp, $sFile) Then
            ConsoleWrite("Image was saved properly!" & @CRLF)
        Else
            ConsoleWrite("Image could not be saved!" & @CRLF)
        Endif
        _GDIPlus_ImageDispose($hBmp)
        _ClipBoard_Empty()
        $hMemoryBMP = 0
    EndIf
    _ClipBoard_Close()
Until False * Sleep(500)

Func _Exit()
    ConsoleWrite("Finished!" & @CRLF)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

Press Shift+Alt+q to exit.

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

Yes, exactly like that there.
But there is one problem. I prtscn'd and then ran the script. It hung. I did not get the dialog or anything else. Not even through the console. It is simply stuck. Had to exit it through the tray icon.
Thank you man, you are a life saver.

3 hours ago, UEZ said:

Something like this here?

#include <GDIPlus.au3>
#include <Clipboard.au3>

_GDIPlus_Startup()
Global $hMemoryBMP = 0, $hBmp, $hWnd = WinGetHandle(AutoItWinGetTitle())
HotKeySet("+!q", "_Exit") ;Shift+Alt+q to exit

_ClipBoard_Open($hWnd)
_ClipBoard_Empty()
_ClipBoard_Close()
Sleep(100)

Do
    If Not _ClipBoard_Open($hWnd) Then
        ConsoleWrite("Could not open clipboard!!!" & @CRLF)
        _Exit()
    EndIf
    $hMemoryBMP = _ClipBoard_GetDataEx($CF_BITMAP)
    If $hMemoryBMP Then
        $sFile = FileSaveDialog("Save Bitmap from Clipboard", "", "Images(*.jpg;*.bmp;*.png;*.gif)")
        If @error Then ContinueLoop
        $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($hMemoryBMP)
        If _GDIPlus_ImageSaveToFile($hBmp, $sFile) Then
            ConsoleWrite("Image was saved properly!" & @CRLF)
        Else
            ConsoleWrite("Image could not be saved!" & @CRLF)
        Endif
        _GDIPlus_ImageDispose($hBmp)
        _ClipBoard_Empty()
        $hMemoryBMP = 0
    EndIf
    _ClipBoard_Close()
Until False * Sleep(500)

Func _Exit()
    ConsoleWrite("Finished!" & @CRLF)
    _GDIPlus_Shutdown()
    Exit
EndFunc

 

Press Shift+Alt+q to exit.

 

Yes, exactly like that there.
But there is one problem. I prtscn'd and then ran the script. It hung. I did not get the dialog or anything else. Not even through the console. It is simply stuck. Had to exit it through the tray icon.
Thank you man, you are a life saver.

EDIT: My dumb butt placed my reply inside of your quote.

 

EDIT TWice
I ran it for a min, and it finally exited with an error.

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Draygoes\Desktop\savefileengine.au3"    
Could not open clipboard!!!
Finished!
>Exit code: 0    Time: 183

Ok, so I never learned the GDI+ Library. So this is very new territory for me. I WILL learn it later on, but I do wish to finish the project that I am currently working on in the next few hours. B)

 

Edited by Draygoes
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Reading your code, it looks like Print Screen is not saving to clipboard. But it is, as I can copy to any image editor.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

When I press the print screen key it popups with the save dialog window.

Try with 

$hWnd = 0

 

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

@mikell I don't think so. I had this function also in Windows Screenshooter implemented which can monitor the clipboard but in the core it is the same.

To be honest I forgot your post and I posted nothing new or special. Reason is probably that I'm concentrated in coding with FB. :)

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

9 hours ago, UEZ said:

When I press the print screen key it popups with the save dialog window.

Try with 

$hWnd = 0

 

Would you be willing to elaborate? I cannot see where that would fit in your code...

EDIT: I just tried to run that same code on my laptop and got the same result. It does not work.

Edited by Draygoes
Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

What I ultimately needed to do was save a screenshot to a specified folder. Being able to save any image from the clipboard to file would simply be a bonus.
I found a program that takes care of the main need just fine. Its called Nircmd, and taking a screen shot is one of many things it can do.

Thank you all for your help and your time. All the helpful people here is one of the reasons that I love this place.
I want to leave this open because a workable solution to the OP would still be helpful.

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

Why get and save from the clipboard? I feel this function does it much better in one go

https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_SaveImage.htm

and maybe translate this vba Excel  to AutoIt 

http://www.ms-office-forum.net/forum/sitemap/index.php?t-335549.html

 

 

Edited by junkew
Link to comment
Share on other sites

Yeah, do you really need to retrieve a screenshot? Can't you just use a piece of code that screenshots and saves the file to where you want?

Just take this as an example of an active window screenshot

#include <ScreenCapture.au3>

_ScreenCapture_SetJPGQuality(100);max image quality
$scrFile = @DesktopDir & "\screenshot - " & @MDAY & @MON & @YEAR & '-' & @HOUR &@MIN& @SEC & ".jpg"
_ScreenCapture_CaptureWnd($scrFile, "[ACTIVE]", -1, -1, -1, -1, 0)

 

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

On 1/24/2018 at 10:34 AM, junkew said:

Why get and save from the clipboard? I feel this function does it much better in one go

https://www.autoitscript.com/autoit3/docs/libfunctions/_ScreenCapture_SaveImage.htm

and maybe translate this vba Excel  to AutoIt 

http://www.ms-office-forum.net/forum/sitemap/index.php?t-335549.html

 

 

 

2 hours ago, careca said:

Yeah, do you really need to retrieve a screenshot? Can't you just use a piece of code that screenshots and saves the file to where you want?

Just take this as an example of an active window screenshot

#include <ScreenCapture.au3>

_ScreenCapture_SetJPGQuality(100);max image quality
$scrFile = @DesktopDir & "\screenshot - " & @MDAY & @MON & @YEAR & '-' & @HOUR &@MIN& @SEC & ".jpg"
_ScreenCapture_CaptureWnd($scrFile, "[ACTIVE]", -1, -1, -1, -1, 0)

 

I, had no idea these where a thing! Thanks all!!!

Spoiler

 

"If a vegetarian eats vegetables,What the heck does a humanitarian eat?"

"I hear voices in my head, but I ignore them and continue on killing."

"You have forced me to raise the indifference warning to beige, it's a beige alert people. As with all beige alerts please prepare to think about the possibility of caring."

An optimist says that giving someone power DOESN'T immediately turn them into a sadist. A pessimist says that giving someone power doesn't IMMEDIATELY turn them into a sadist.

 

 
Link to comment
Share on other sites

ok combine it with a hotkey ctrl+q for example and increment the number of your screenshot to save somewhere or use timestamp

https://www.autoitscript.com/autoit3/docs/functions/HotKeySet.htm

Use this stuff frequently myself to just make a quick sequence of screenshots to explain the flow to people

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...