How to access the print screen image?

Asked

Viewed 73,740 times

10

When we hit the button Print Screen from our keyboard, the screen image is saved in some cache, in memory, somewhere, because when we give Ctrl V after, in Paint for example it trims, how to access the location and "pick up" the image from there in C#?

2 answers

13


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

Under . NET, you can access and interact with the clipboard through some classes that have the same name, although they are on namespaces different. 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 method GetImage you get an object that contains your image.

9

A code ready for use complementing the response of Renan:

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

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

I put in the Github for future reference.

You can still use a most complete solution.

  • Correct me if I’m wrong, but I believe you’ve mistaken using the using to the correct using static, as the members below are not declared and would probably cause an error in the compilation.

  • 1

    @Cypherpotato when I did this was still creating this feature and at first it was without the static, after they decided to demand the static in this context. Thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.