jeudi 2 avril 2015

Image to byte array - ExternalException

I'm trying to read an image from an EID with a card reader and convert it to a byte array for database storage.


Reading the image works perfectly. I'm able to retreive a valid image with these properties: enter image description here


However, I cannot convert it to a byte array. I'm using this code, although I've tried other approaches to convert it already:



public static byte[] ImageToBytes(Image image)
{
MemoryStream stream = new MemoryStream();
image.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
return stream.ToArray();

}


Calling the Save method gives following exception:



An exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll but was not handled in user code


The details of the exception does not clear anything up. It's a general exception with no information about what went wrong.


Any ideas what I've been doing incorrectly?


Aucun commentaire:

Enregistrer un commentaire