【问题标题】:Taking a screenshot of the desktop in C#在 C# 中截取桌面的屏幕截图
【发布时间】:2014-07-31 05:59:32
【问题描述】:

我收到一条错误消息,提示在运行时 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();
                }
}

【问题讨论】:

  • 当你说“错误”时,你是指编译器还是运行时?
  • 这些都没有保存到“MemoryStream”对象,所以我认为它的处理方式不同。不知道为什么疯狂的反对票。有人教别人一些东西,我们否决了这个问题?这些链接与我的问题并不完全相同,因为它们将它们保存到磁盘。

标签: c# .net


【解决方案1】:

将该行更改为

bmpScreenCapture.Save(ms, ImageFormat.Png); 

顺便说一句:您可以使用 ImageFormat 支持的任何格式

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.imageformat(v=vs.110).aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-19
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多