B
brenny
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.Create,FileAccess.Write);
MemoryStream ms = new MemoryStream();
i.Save(ms,ImageFormat.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 openFileDialogPicture = new OpenFileDialog();
openFileDialogPicture.InitialDirectory = "C:\\temp\\image.jpg";
openFileDialogPicture.Filter = "picture files (*.jpg)|*.jpg";
openFileDialogPicture.FilterIndex = 2 ;
openFileDialogPicture.RestoreDirectory = true ;
if(openFileDialogPicture.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialogPicture.OpenFile())!= null)
{
path = openFileDialogPicture.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.Create,FileAccess.Write);
MemoryStream ms = new MemoryStream();
i.Save(ms,ImageFormat.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 openFileDialogPicture = new OpenFileDialog();
openFileDialogPicture.InitialDirectory = "C:\\temp\\image.jpg";
openFileDialogPicture.Filter = "picture files (*.jpg)|*.jpg";
openFileDialogPicture.FilterIndex = 2 ;
openFileDialogPicture.RestoreDirectory = true ;
if(openFileDialogPicture.ShowDialog() == DialogResult.OK)
{
if((myStream = openFileDialogPicture.OpenFile())!= null)
{
path = openFileDialogPicture.FileName;
Image i = Image.FromFile(path);
}
}
finally,How can I save this image object to specified path.
Thanks.