Deepak M

Deepak M

  • 1.2k
  • 546
  • 36.8k

How to take full screenshot of desktop ?

Oct 18 2023 7:25 AM

I have below code to take screenshot and it's working, but the problem is it crop the image from the buttom and save it. I want to take full desktop screenshot.

using System;
using System.Drawing;
using System.Windows.Forms;

namespace MyApp
{
    class ScreenCapture
    {
        internal static void ScreenShort()
        {
            // Start the process... 
            Bitmap memoryImage;
            memoryImage = new Bitmap(SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height);
            Size s = new Size(memoryImage.Width, memoryImage.Height);

            // Create graphics 
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);

            // Copy data from screen 
            memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);

            //That's it! Save the image in the directory and this will work like charm. 
            string str = "";
            try
            {
                str = string.Format(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Screenshot.png");
            }
            catch (Exception er)
            {
                Console.WriteLine("Sorry, there was an error: " + er.Message);
                Console.WriteLine();
            }

            // Save it! 
            memoryImage.Save(str);

            // Write the message, 
            Console.WriteLine("Picture has been saved...");
            Console.WriteLine();
        }
    }
}


Any advice or suggestions would be greatly appreciated.


Answers (1)