How do I create a bitmapimage object from a byte array. Here's my code:
System.Windows.Media.Imaging.BitmapImage image = new
System.Windows.Media.Imaging.BitmapImage();
byte[] data = new byte[10] { 1, 0, 0, 1, 1, 1, 0, 0, 1, 0 };
using (var ms = new System.IO.MemoryStream(data))
{
image.BeginInit();
image.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.OnLoad;
image.StreamSource = ms;
image.EndInit();
}
When running the EndInit() command, I got the following exception.
No imaging component suitable to complete this operation was found.
I expected that these lines should create an image of dimension 1x10 pixels, containing two colors.
What am I doing wrong? What does the exception mean?
Thanks in advance!