Search code examples
c#windowsimagescreen-grab

How to grab an image and save it in a folder [c# windows application]


I am Creating an windows application using c#.I have a button which should capture the image(the entire Desktop screen) and Save it in a folder .Also i need to show the preview of the image .


Solution

  • Graphics.CopyFromScreen Method

    sample code:

    Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Size.Width, Screen.PrimaryScreen.Bounds.Size.Height);
    Graphics g = Graphics.FromImage(bmp);
    g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
    g.Save();
    bmp.Save("D:\\file.jpg", ImageFormat.Bmp);
    

    as for show the preview. IMO not that hard to write it on ur own.