Ошибка при экспорте изображения из picturebox » В GDI произошла общая ошибка «. C#

#c#

#c#

Вопрос:

У меня ошибка при экспорте изображения из PictureBox

» В GDI произошла общая ошибка »

********** Текст исключения **********

 System.Runtime.InteropServices.ExternalException (0x80004005): 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 Soccer_Studio.Form1.button2_Click(Object sender, EventArgs e) in ***********************Form1.cs:line 137
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Messageamp; m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Messageamp; m)
at System.Windows.Forms.ButtonBase.WndProc(Messageamp; m)
at System.Windows.Forms.Button.WndProc(Messageamp; m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Messageamp; m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Messageamp; m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
 

Это мой код

  using (Bitmap tempImage = new Bitmap(pictureBox1.Image))
            {
                pictureBox1.Image.Save(@"C:UsersMenaDesktop", System.Drawing.Imaging.ImageFormat.Bmp);
            }
 

В чем проблема в коде?

Комментарии:

1. A generic error occurred in GDI , это действительно не говорит слишком много. Что говорит отладчик?

Ответ №1:

Возможно, вам понадобится имя файла…

 pictureBox1.Image.Save(@"C:UsersMenaDesktopfile.bmp",
    System.Drawing.Imaging.ImageFormat.Bmp);
 

Комментарии:

1. Акцент file.bmp на пути.