no decode delegate for this image format
Description
I have a WriteableBitmap and want to create a MagickImage from it. I added the WriteableBitmapEx Extensions and using the ToByteArray Method like this:
var image = new MagickImage(Image.ToByteArray())
it does throw
ImageMagick.MagickMissingDelegateErrorException
HResult=0x80131500
Nachricht = no decode delegate for this image format `' @ error/blob.c/BlobToImage/458
Quelle = Magick.NET-Q8-x64
Stapelüberwachung:
at ImageMagick.NativeInstance.CheckException(IntPtr exception, IntPtr result)
at ImageMagick.MagickImage.NativeMagickImage.ReadBlob(MagickSettings settings, Byte[] data, Int32 offset, Int32 length)
at ImageMagick.MagickImage.Read(Byte[] data, Int32 offset, Int32 length, MagickReadSettings readSettings, Boolean ping)
at ImageMagick.MagickImage.Read(Byte[] data, MagickReadSettings readSettings)
at ImageMagick.MagickImage..ctor(Byte[] data)
System Configuration
- Magick.NET version: Magick.NET-Q8-x64
- Environment (Operating system, version and so on): win10
What is the format of your Image? I suspect it is a format that is not recognized by Magick.NET by the header of the image data. Can you share a more complete example to demonstrate this issue?
hi, a sample code would be:
BitmapImage bitmap = new BitmapImage(new Uri("1080x720.jpg")); // Just for demo, only WriteableBitmap is available in real WPF Project
WriteableBitmap img = new WriteableBitmap(bitmap); // WPF Image Format
var image = new MagickImage(img .ToByteArray());
just reference the WriteableBitmapEx from nuget for the ToByteArray Extension Method
i added this method
public static byte[] ImageToBytee(WriteableBitmap imageSource)
{
var encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(imageSource));
using (var ms = new MemoryStream())
{
encoder.Save(ms);
return ms.ToArray();
}
}
and now the bmp data is accepted but its perfomance is bad, it would be great if a constructor for WriteableBitmap /BitmapSource like for Bitmap would be available
That it the same trick as that I am using in the Bitmap constructor but we could probably do this a lot more efficient by copying the pixels. Will take a look at this in the future.