TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
David Zhou
NA
1
14.2k
Saving Clipboard PrintScreen to Image File in C#
May 31 2013 10:48 AM
Hello Everyone,
I'm a new poster here and apologize in advance if I have posted this in the wrong subforum.
I am trying to use Visual Studio C# to printscreen, then save the screen capture to a file.
Currently, I am having problems reading from the clipboard. I have tried using both of the following lines to save a screen capture to the clipboard:
SendKeys.SendWait("+{PRTSC}");
SendKeys.SendWait("{PRTSC}");
However, when I try to save the image using the following lines, I get a Null Reference Exception.
image = (Image)Clipboard.GetDataObject().GetData(DataFormats.Bitmap);
image.Save("image.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
I have tested if the clipboard actually contains an image, and the following lines indicate that it thinks the clipboard is empty. i.e. the program writes "Clipboard empty."
if (Clipboard.GetDataObject() == null)
{
Console.WriteLine("Clipboard empty.");
}
However, I know that it is not empty since I can paste the screen capture to paint after running the code.
I have looked at many tutorials on how to save screenshots to image files and don't know what I am doing wrong here. Any help would be much appreciated.
Thanks!
Reply
Answers (
2
)
how can i make dictionary display images and text in array ?
I work on Microsoft technologies?