1

I have these lines of code that takes a screenshot and "gets" it:

    SendKeys.Send("{PRTSC}");
    Image img = Clipboard.GetImage();
    initScreenShot = new Bitmap(img);

But some times i get the error message:

An unhandled exception of type 'System.NullReferenceException' occurred in System.Drawing.dll

on the lineinitScreenShot = new Bitmap(img);, this happens about 25% of the times i run the code. Why is that?

user6395724
  • 89
  • 2
  • 7
  • you should try this approach, even better it doesn't mess up with user's clipboard: http://stackoverflow.com/questions/362986/capture-the-screen-into-a-bitmap – Logerfo May 31 '16 at 15:29

0 Answers0