Possible Duplicate:
GDI+ Generic Error
i am writing a db application and use "sdf" file as a database. i save the image on the DB by converting it to a byte array by this code :
byte[] ReadFile(string sPath)
{
//Initialize byte array with a null value initially.
byte[] data = null;
//Use FileInfo object to get file size.
FileInfo fInfo = new FileInfo(sPath);
long numBytes = fInfo.Length;
//Open FileStream to read file
FileStream fStream = new FileStream(sPath, FileMode.Open, FileAccess.Read);
//Use BinaryReader to read file stream into byte array.
BinaryReader br = new BinaryReader(fStream);
//When you use BinaryReader, you need to supply number of bytes to read from file.
//In this case we want to read entire file. So supplying total number of bytes.
data = br.ReadBytes((int)numBytes);
return data;
}
and insert it into database.
i retrive the image via this code:
public static Image CreateImage(byte[] imageData)
{
Image image=null;
if(imageData !=null)
{
using (MemoryStream inStream = new MemoryStream())
{
inStream.Write(imageData, 0, imageData.Length);
image = Bitmap.FromStream(inStream);
}
}
return image;
}
and assign the pictureBox Image to CreateImage return value.
until here every thing is fine but when i want to store pictureBox image on the disk
Bpicture.Image.Save(@"pic1.jpeg", ImageFormat.Jpeg);
this error occurs :
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
Additional information: A generic error occurred in GDI+.
also this error doesn't happen when i load image from disk instead of database