i'm storing an image in a database, when i pull it out i'm converting the binary data to an image, using thing following method:
public static System.Drawing.Image GetImage(byte[] byteArray)
{
//---- create a memory stream from the byte array
using (Stream stream = new MemoryStream(byteArray, true))
{
stream.Write(byteArray, 0, byteArray.Length);
//---- create and return a new bitmap from that stream
return System.Drawing.Bitmap.FromStream(stream, true);
}
}
but when i call it i'm getting the error, "Paramter is not valid." on the FromStream() call.any ideas on how to debug this? it's a classic gdi+ error case where it gives me no information about what's actually going on.
bryanc
Member
302 Points
128 Posts
Parameter is not valid. error when using System.Drawing.Bitmap.FromStream
May 13, 2007 03:22 AM|LINK
hi,
i'm storing an image in a database, when i pull it out i'm converting the binary data to an image, using thing following method:
public static System.Drawing.Image GetImage(byte[] byteArray){
//---- create a memory stream from the byte array
using (Stream stream = new MemoryStream(byteArray, true))
{
stream.Write(byteArray, 0, byteArray.Length);
//---- create and return a new bitmap from that stream
return System.Drawing.Bitmap.FromStream(stream, true);
}
}
but when i call it i'm getting the error, "Paramter is not valid." on the FromStream() call.any ideas on how to debug this? it's a classic gdi+ error case where it gives me no information about what's actually going on.
-b
bryanc
Member
302 Points
128 Posts
Re: Parameter is not valid. error when using System.Drawing.Bitmap.FromStream
May 16, 2007 12:04 AM|LINK
this works:
ImageConverter imageConverter = new System.Drawing.ImageConverter();
Image image = imageConverter.ConvertFrom(byteArray) as Image;
jean quiero
Member
2 Points
1 Post
Re: Parameter is not valid. error when using System.Drawing.Bitmap.FromStream
Jan 08, 2010 02:59 AM|LINK
thanks to you man, you save my day.....
this code works perfect