[英]Getting “A generic error occurred in GDI+” in C#
當用戶按下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”驅動器是否確實存在。 還要檢查防火牆是否阻止程序創建文件,或者是否已經有其他同名文件阻止寫入。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.