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 #?
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 #?
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:
System.Windows.Clipboard
(clipboard is the name of the clipboard in English); System.Windows.Forms.Clipboard
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.
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 .