【发布时间】:2012-07-06 19:18:27
【问题描述】:
我正在尝试将用户的整个桌面捕获为图像。我通过以下方式做到这一点:
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;
}
但是,如果我尝试将 PixelFormat 从 Format32bppArgb 更改为 Format16bppArgb1555,它会产生一个 OutOfMemoryException,考虑到我降低了质量,我不太明白。
有什么想法吗?或者我怎样才能降低这张图片的质量(因为它会以非常频繁的间隔通过网络发送)
【问题讨论】:
-
何时会发生 OOM?我想这是在转换过程中,而不是最终结果。
-
发生在
using (Graphics g = Graphics.FromImage(CapturedImage))这一行
标签: c# networking graphics bitmap