I want to save images in an access database, I used an OLE object.
The idea is to convert the image to an array of bytes, and then add an array of bytes to the database.
this is the function:
public static byte[] ImageToByte(Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}
it works great.
When I want to return an array of bytes to an image, I get an exception:
Argument exceptionUnhandled Invalid parameter.
I tried two functions to convert an array of bytes to an image:
public static Image ImageFromByte(byte[] image)
{
ImageConverter ic = new ImageConverter();
Image img = (Image)ic.ConvertFrom(image);
return img;
}
OR
public static Image ImageFromByte1(byte[] byteArrayIn)
{
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
What is the problem, how to fix it?
source
share