Hello
I want to save a image to specified path as a jpg format.
But I'm getting some error messages.
Codes are shown below ;
path ="C:\\image.jpg ";
FileStream fs = new FileStream(path ,FileMode.Creat e,FileAccess.Wr ite);
MemoryStream ms = new MemoryStream();
i.Save(ms,Image Format.Jpeg);
byte[] b = new byte[ms.Length];
ms.Write(b,0,b. Length);
fs.Write(b,0,b. Length);
fs.Close();
i is image object,it was loaded from anywhere(from path or database),
We suppose that size of i object is 223 kb and after codes mentioned above a
image is saved and it's size is 223kb but,picture in the saved file is not
appear.
i object is load with codes below;
String path;
Stream myStream;
OpenFileDialog openFileDialogP icture = new OpenFileDialog( );
openFileDialogP icture.InitialD irectory = "C:\\temp\\imag e.jpg";
openFileDialogP icture.Filter = "picture files (*.jpg)|*.jpg";
openFileDialogP icture.FilterIn dex = 2 ;
openFileDialogP icture.RestoreD irectory = true ;
if(openFileDial ogPicture.ShowD ialog() == DialogResult.OK )
{
if((myStream = openFileDialogP icture.OpenFile ())!= null)
{
path = openFileDialogP icture.FileName ;
Image i = Image.FromFile( path);
}
}
finally,How can I save this image object to specified path.
Thanks.
I want to save a image to specified path as a jpg format.
But I'm getting some error messages.
Codes are shown below ;
path ="C:\\image.jpg ";
FileStream fs = new FileStream(path ,FileMode.Creat e,FileAccess.Wr ite);
MemoryStream ms = new MemoryStream();
i.Save(ms,Image Format.Jpeg);
byte[] b = new byte[ms.Length];
ms.Write(b,0,b. Length);
fs.Write(b,0,b. Length);
fs.Close();
i is image object,it was loaded from anywhere(from path or database),
We suppose that size of i object is 223 kb and after codes mentioned above a
image is saved and it's size is 223kb but,picture in the saved file is not
appear.
i object is load with codes below;
String path;
Stream myStream;
OpenFileDialog openFileDialogP icture = new OpenFileDialog( );
openFileDialogP icture.InitialD irectory = "C:\\temp\\imag e.jpg";
openFileDialogP icture.Filter = "picture files (*.jpg)|*.jpg";
openFileDialogP icture.FilterIn dex = 2 ;
openFileDialogP icture.RestoreD irectory = true ;
if(openFileDial ogPicture.ShowD ialog() == DialogResult.OK )
{
if((myStream = openFileDialogP icture.OpenFile ())!= null)
{
path = openFileDialogP icture.FileName ;
Image i = Image.FromFile( path);
}
}
finally,How can I save this image object to specified path.
Thanks.
Comment