I try to create a screenshot like described here:
private Graphics takeScreenshot()
{
//Create a new bitmap.
var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);
// Create a graphics object from the bitmap.
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
return gfxScreenshot;
}
How can I show it in my form after it is taken? I tried to display it inside a pictureBox:
Graphics screenshot = takeScreenshot();
pictureBox1.Image = screenshot;
But I get:
Severity Code Description Project File Line Suppression State Error CS0029 Cannot implicitly convert type 'System.Drawing.Graphics' to 'System.Drawing.Image' SRAT C:\Users\Edd\documents\visual studio 2017\Projects\SRAT\SRAT\Form1.cs 20 Active
and this answer says that it is not possible to convert it