简体   繁体   中英

Error in exporting image from picturebox “ A generic error occurred in GDI+. ” C#

I have an error when exporting image from pictureBox

" A generic error occurred in GDI+ "

********** Exception Text **********

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(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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)

This is my code

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

What is the problem in the code ?

You might need a filename...

pictureBox1.Image.Save(@"C:\Users\Mena\Desktop\file.bmp",
    System.Drawing.Imaging.ImageFormat.Bmp);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM