我收到错误,说运行时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();
}
}
答案 0 :(得分:1)
将该行更改为
bmpScreenCapture.Save(ms, ImageFormat.Png);
BTW:您可以使用 ImageFormat 支持的任何格式
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat(v=vs.110).aspx