I’m trying to capture the user’s entire desktop as an image. I do this in the following way:
public Bitmap CaptureScreen()
{
// Set up a bitmap of the correct size
Bitmap CapturedImage = new Bitmap((int)SystemInformation.VirtualScreen.Width,
(int)SystemInformation.VirtualScreen.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
// Create a graphics object from it
System.Drawing.Size size = new System.Drawing.Size((int)SystemInformation.VirtualScreen.Width, (int)SystemInformation.VirtualScreen.Height);
using (Graphics g = Graphics.FromImage(CapturedImage))
{
// copy the entire screen to the bitmap
g.CopyFromScreen(0, 0, 0, 0,
size, CopyPixelOperation.SourceCopy);
}
return CapturedImage;
}
However, if I try to change the PixelFormat from Format32bppArgb to Format16bppArgb1555, it produces an OutOfMemoryException, which I don’t really understand, considering I’ve lowered the quality.
Any ideas? Or how can I reduce the quality of this image (as it will be being sent over the network at quite frequent intervals)
From the docs: (also related)
In the “related” link, msdn goes on to say that: