I am trying to save an image from a picturebox1 element in a windows form, but the Image.Save
method throws a parameter not valid exception and I can't work out why.
string name = "BookCover_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpeg";
string path = pathFolder + name;
if (Directory.Exists(pathFolder))
{
pictureBox1.Image.Save(path, ImageFormat.Jpeg);
}
This is the error message that I am getting:
System.ArgumentException
HResult=0x80070057
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at LibraryProject.Forms.CameraForm.btnSave_Click(Object sender, EventArgs e) in C:\git\libraryproject\LibraryProject.Core\LibraryProject.Forms\CameraForm.cs:line 172
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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at LibraryProject.Forms.Program.Main() in C:\git\libraryproject\LibraryProject.Core\LibraryProject.Forms\Program.cs:line 19
User contributions licensed under CC BY-SA 3.0