GDI +错误,保存截图

时间:2013-08-16 17:51:25

标签: c# visual-studio generics gdi+ screenshot

我看到很多线程有GDI +错误,有些是针对网页图片,其他是表单图片编辑...只有一个用于截图: Generic error in GDI+ occurs in Screen Capture 并没有解决方案。 我正在关注this guide

和我的“唯一截图程序”是:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.IO;



namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        private static Bitmap bmpScreenshot;
        private static Graphics gfxScreenshot;
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
            gfxScreenshot = Graphics.FromImage(bmpScreenshot);
            gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
            bmpScreenshot.Save("c:\\test.png", ImageFormat.Png);
            this.Show();
          }
    }
}

但是我在GDI +中收到了一般错误。它应该隐藏,取屏,保存并取消隐藏。 相反,它会阻止并排除该错误:

bmpScreenshot.Save("c:\\test.png", ImageFormat.Png);

感谢阅读,对不起,如果我“发明”了新语法,我不是英语!

0 个答案:

没有答案