C# 获得;GDI+;中发生一般性错误&引用;在C中#

C# 获得;GDI+;中发生一般性错误&引用;在C中#,c#,winforms,save,C#,Winforms,Save,我编写了一个非常简单的代码,当用户按CTRL+V键时从剪贴板获取图像。然后我将该图像保存到静态位置: public partial class Form1 : Form { public Form1() { InitializeComponent(); } public System.Drawing.Image GetClipboardImage() { System.Drawing.Image returnImage =

我编写了一个非常简单的代码,当用户按CTRL+V键时从剪贴板获取图像。然后我将该图像保存到静态位置:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    public System.Drawing.Image GetClipboardImage()
    {
        System.Drawing.Image returnImage = null;
        if (Clipboard.ContainsImage())
        {
            returnImage = Clipboard.GetImage();
        }
        return returnImage;
    }

    private void Form1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control)
        {
            Image img = GetClipboardImage();

            // ******* IT THROWS THE ERROR HERE*****************
            img.Save(@"C:\LOGO_ARTWORK_TEMP_IMAGE.jpeg", ImageFormat.Jpeg);

            this.Close();
        }
    }
}
我试图保存图像时出错。这个程序在我的系统上运行得很好,但在客户的服务器上不工作是关于权限的吗

例外情况如下:

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
   at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
   at System.Drawing.Image.Save(String filename, ImageFormat format)
   at LOGO_IMAGE_COPY_PASTE.Form1.Form1_KeyDown(Object sender, KeyEventArgs e) in D:\PROJELER\LOGO_IMAGE_COPY_PASTE\LOGO_IMAGE_COPY_PASTE\Form1.cs:line 36
   at System.Windows.Forms.Control.OnKeyDown(KeyEventArgs e)
   at System.Windows.Forms.Control.ProcessKeyEventArgs(Message& m)
   at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
   at System.Windows.Forms.Control.WmKeyChar(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

您似乎不太可能拥有客户服务器上
C:\
的写入权限。除了运行程序外,您是否可以在其中创建文件?

检查粘贴的图像数据是否有效。然后检查权限并验证“C”驱动器是否确实存在。还要检查防火墙是否阻止程序创建文件,或者是否已经有其他同名文件阻止写入