当我尝试保存图像时,我收到错误“GDI +中发生了一般错误”。

时间:2012-07-29 01:38:10

标签: c# bitmap gif save

当我运行此代码时,在我评论的行上,我总是得到一个" GDI +中发生了一般错误。"运行时错误

    private void ConstructFromResourceSaveAsGif()
    {
        Bitmap bmp1 = new Bitmap(typeof(Button), "Button.bmp");

        //This line
        bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);
    }

2 个答案:

答案 0 :(得分:2)

您可以使用代码

private void ConstructFromResourceSaveAsGif()
{
    Bitmap bmp1 = new Bitmap("Button.bmp");

    bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);
}

它仍然有效,除非你试图完成@DanF所说的话。

修改

这是我用来测试它的快速应用程序:

class Program
{
    static void Main(string[] args)
    {
        Bitmap bmp1 = new Bitmap("C:/donut.jpg");

        bmp1.Save("c:\\button.gif", System.Drawing.Imaging.ImageFormat.Gif);

        Console.WriteLine("Save Success");
        Console.Read();
    }
}

答案 1 :(得分:2)

  

此构造函数将给定类型的命名空间与   资源的字符串名称,并在程序集中查找匹配项   表现。例如,您可以传递Button类型和Button.bmp   到这个构造函数,它将查找名为的资源   System.Windows.Forms.Button.bmp

你有一个名为的资源吗?如果没有,这将是你的问题。 “发生了一般性错误...”是GDI +不是非常友好的方式将手伸向空中并说“它已经破了,但我不会告诉你为什么”