How to access the print screen image?

9

When we press the Print Screen key on our keyboard, the screen image is saved in some memory cache, somewhere, because when we give Ctrl V after, in Paint for example it apararece, how to access the location and "catch" the image from there in C #?

    
asked by anonymous 05.05.2014 / 14:04

2 answers

10

When you use the Print Screen key, a copy of what's on the screen goes to Clipboard . It's the same place where any information you copy or cut goes.

In .NET, you can access and interact with the clipboard through some classes that have the same name, even though they are in different namespaces . The ones I know are:

Note that the methods are basically the same. You can check the type of content in the clipboard - ContainsImage will tell you if it is an image - and with the GetImage method you get an object that contains your image.

    
05.05.2014 / 14:22
6

A ready-to-use code complementing Renan's answer:

using System.Drawing.Imaging.ImageFormat; //Somente à partir do C# 6
using System.Clipboard; //Somente à partir do C# 6, caso contrário, use apenas o namespace

if (ContainsImage())  
    GetImage().Save(@"image.jpeg", Jpeg);

I placed it on GitHub for future reference.

You can even use a more complete solution .

    
28.08.2014 / 20:16