I’m desperately trying to save an image to an SQL database and then load it on my WP. All of the guides online say to convert the image to a Byte array, store it and then load it back into an image.
So far, I’ve been able to save the image into a Byte array using:
public static byte[] ConvertToBytes(Stream photoStream)
{
byte[] a = new Byte[photoStream.Length];
for (int i = 0; i < photoStream.Length; i++)
{
a[i] = (Byte)photoStream.ReadByte();
}
return (a);
}
This generates a Byte array that is similar in size to the image I’m saving.
The suggested way to load images is:
1 public static BitmapImage ConvertToImage(Byte[] inputBytes)
2 {
3 MemoryStream stream = new MemoryStream(inputBytes);
4 BitmapImage image = new BitmapImage();
5 image.SetSource(stream);
6 return (image);
7 }
This doesn’t work.
I get this error (on line 5):
“Unspecified error”
Does anybody have any idea how to fix this or can suggest an alternative method/code?
I know there is information online – i can assure you that i have searched long and hard for a working method and been able to make nothing work.
Any help would be much appreciated!
I managed to solve this using:
Thanks for all your help guys.