I am storing images in a database and would like to convert them from byte array to image. I have no problem converting an object to byte array but I get an error of \"Param
Try to deserialize the object first from byte array with your BinaryFormatter!
Try to use following two methods:
private System.Drawing.Image ObjToImg(byte[] obj)
{
if (obj == null)
return null;
else
{
BinaryFormatter bf = new BinaryFormatter();
using(MemoryStream ms = new MemoryStream(obj))
{
return (System.Drawing.Image)bf.Deserialize(ms);
}
}
}
private byte[] ImgToObj(System.Drawing.Image obj)
{
if (obj == null)
return null;
else
{
BinaryFormatter bf = new BinaryFormatter();
using(MemoryStream ms = new MemoryStream())
{
bf.Serialize(ms, obj);
return ms.ToArray();
}
}
}