Want to convert byte[] to Imagesource
here is my code for convert to byte
public object BufferFromImage(System.Windows.Media.ImageSource imageSource)
{
if (imageSource != null)
{
var image = (BitmapSource)imageSource;
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(image));
using (var ms = new MemoryStream())
{
encoder.Save(ms);
return ms.ToArray();
}
}
else
{
return DBNull.Value;
}
}
code for byte[] to Imagesource
public ImageSource ByteToImage(byte[] imageData)
{
BitmapImage biImg = new BitmapImage();
MemoryStream ms = new MemoryStream(imageData);
biImg.BeginInit();
biImg.StreamSource = ms;
biImg.EndInit();
ImageSource imgSrc = biImg as ImageSource;
return imgSrc;
}
This is giving me this error:
An unhandled exception of type 'System.NotSupportedException' occurred in PresentationCore.dll
Additional information: No imaging component suitable to complete this operation was found.
What is causing this and how can I fix it?