Magick.NET icon indicating copy to clipboard operation
Magick.NET copied to clipboard

no decode delegate for this image format

Open simonbuehler opened this issue 6 years ago • 4 comments

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

simonbuehler avatar Mar 10 '20 11:03 simonbuehler

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?

dlemstra avatar Mar 10 '20 11:03 dlemstra

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

simonbuehler avatar Mar 10 '20 12:03 simonbuehler

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

simonbuehler avatar Mar 10 '20 13:03 simonbuehler

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.

dlemstra avatar Mar 10 '20 21:03 dlemstra