-2

Below code is taking screenshot of desktop window only. My expectation is to take screenshot with taskbar and everything visible to the user.

Any help would be appreciated

''' {

       //Creating a new Bitmap object

      Bitmap captureBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb);

   
     //Bitmap captureBitmap = new Bitmap(int width, int height, PixelFormat);

     //Creating a Rectangle object which will  

     //capture our Current Screen

     Rectangle captureRectangle = Screen.AllScreens[0].Bounds;



     //Creating a New Graphics Object

     Graphics captureGraphics = Graphics.FromImage(captureBitmap);



    //Copying Image from The Screen

    captureGraphics.CopyFromScreen(captureRectangle.Left,captureRectangle.Top,0,0,captureRectangle.Size);



    //Saving the Image File (I am here Saving it in My E drive).

    captureBitmap.Save(@"E:\Capture.jpg",ImageFormat.Jpeg);



    //Displaying the Successfull Result



    MessageBox.Show("Screen Captured");

}

'''

  • You have to change Bitmap captureBitmap = new Bitmap(1024, 768, PixelFormat.Format32bppArgb); to Bitmap captureBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); Your bitmap was to small – Triims Oct 27 '20 at 09:47
  • @Triims, I tried with below code also.but still i am not getting task bar var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb); – Vignesh Chat Oct 27 '20 at 09:49
  • Thats weird, I tested it and by changing that line it worked for me. Is a file created at that location? – Triims Oct 27 '20 at 09:53
  • https://stackoverflow.com/a/13228495/17034 – Hans Passant Oct 27 '20 at 10:05
  • There's no question. Read [ask]. – IInspectable Oct 27 '20 at 17:59

1 Answers1

1

This should work fine for you, duplicate question here

Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, 
                                    Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap as Image);
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
Tom James
  • 26
  • 3