I've got a SQL Server database in which I store PNG's. The value of the screenshot is in Hex (0x085A3B...). How can I convert from "Screenshot" (my own data type) to "Image" or something similar like "BitmapImage"?
For the beginning, I fetch a screenshot like this:
private Screenshot LoadScreenshot()
{
using (var context = new Context())
{
return context.Screenshots.FirstOrDefault();
}
}
the method above returns me a byte-array like
byte[40864]
I cant do the following because I get an Exception (I dont know which one and why):
public BitmapImage ImageFromBuffer(Byte[] bytes)
{
MemoryStream stream = new MemoryStream(bytes);
BitmapImage image = new BitmapImage();
image.BeginInit();
image.StreamSource = stream;
image.EndInit(); //the compiler breaks here
return image;
}
I'm using C# and WPF
Thank you
EDIT:
Here's my exception:
System.Runtime.Serialization.SafeSerializationManager No imaging component suitable to complete this operation was found
HOW TO SOLVE:
I needed to add this line of code:
Byte[] screenshotBytes = screenshot.Screenshot; //.Screenshot is a byte [] (I dont knwo why it didnt work before)
And @frebinfrancis method