用c#截图桌面
本文关键字:桌面 | 更新日期: 2023-09-27 18:15:46
我得到一个错误,说在运行时Save()行上需要编码器参数。我不知道我应该为这个参数写什么。什么好主意吗?
using (Bitmap bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height))
{
using (Graphics g = Graphics.FromImage(bmpScreenCapture))
{
g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0, 0,
bmpScreenCapture.Size,
CopyPixelOperation.SourceCopy);
MemoryStream ms = new MemoryStream();
bmpScreenCapture.Save(ms, bmpScreenCapture.RawFormat); // <---- ERROR
byte[] bytes = ms.GetBuffer();
ms.Close();
}
}
将该行改为
bmpScreenCapture.Save(ms, ImageFormat.Png);
你可以使用ImageFormat支持的任何格式
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat (v = vs.110) . aspx