ImageConverter throws ArgumentNullException
new ImageConverter().ConvertTo(new Bitmap(100, 100), typeof(byte[]));
System.ArgumentNullException : Value cannot be null.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
at System.Drawing.ImageConverter.ConvertTo(ITypeDescriptorContext context, CultureInfo culture, Object value, Type destinationType)
at System.ComponentModel.TypeConverter.ConvertTo(Object value, Type destinationType)
@FixBo can you please give us some information about your configuration? Is this Linux, Mac? What distro? If so what version of libgdiplus is being used?
.NET Core 3.0 preview on Windows 10.
What's the expected behavior here?
The root problem is that ImageConverter attempts to save the image using an encoder that matches the Image's original format (Image.RawFormat). The supported encoders are Bmp, Gif, Png, Tiff, and Jpeg.
The RawFormat of a new Bitmap() is MemoryBmp which doesn't have a matching encoder. The ImageConverter would either have to guess which encoder you want, or it has to throw an exception because there is no suitable encoder for the Image's current format.
I believe this is the same as https://github.com/dotnet/corefx/issues/36525