Reputation: 75
`
public Bitmap catchFullScreen()
{ Bitmap r = new Bitmap(SystemInformation.VirtualScreen.Width ,SystemInformation.VirtualScreen.Height);
Rectangle bounds = new Rectangle (0,0,SystemInformation.VirtualScreen.Width ,SystemInformation.VirtualScreen.Height);
using (Bitmap bitmap = new Bitmap(SystemInformation.VirtualScreen.Width ,SystemInformation.VirtualScreen.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(Point.Empty, Point.Empty, bounds.Size);
r = bitmap;
pictureBox1.Image = r;
pictureBox1.Update();
pictureBox1.Refresh();
}
pictureBox2.Image = r; // breakpoint 1
pictureBox2.Update(); // breakpoint 2
pictureBox2.Refresh();
}
pictureBox3.Image = r;
pictureBox3.Update();
pictureBox3.Refresh();
return r;
}
` Here is my capture screenshot, but something strange is going on, picturebox1 and 2 is able to capture , but picturebox3 does not. further more, breakpoint1 works but breakpoint2 never arrives,
Why cant i use this bitmap after i am outside the using routines?? more important it wont return r? suggestions please!
Upvotes: 0
Views: 94
Reputation: 1243
Bitmap is a class, that is a reference type. When you dispose bitmap
you also dispose your r
. If you want to continue using r
while disposing bitmap
, consider using something like Bitmap.Clone.
Upvotes: 3