Jump to content

Recommended Posts

Posted

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.

  Reveal hidden contents
 
Posted

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)

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.

  On 1/22/2018 at 1:53 PM, 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.

 

Expand  

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
  Reveal hidden contents
 
Posted

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

  Reveal hidden contents
 
Posted

@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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted (edited)
  On 1/22/2018 at 6:37 PM, UEZ said:

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

Try with 

$hWnd = 0

 

Expand  

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
  Reveal hidden contents
 
Posted

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.

  Reveal hidden contents
 
Posted (edited)

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
Posted (edited)

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
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted
  On 1/24/2018 at 4:34 PM, 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

 

 

Expand  

 

  On 1/25/2018 at 9:30 PM, 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)

 

Expand  

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

  Reveal hidden contents
 

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
  • Recently Browsing   0 members

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