runtime icon indicating copy to clipboard operation
runtime copied to clipboard

ImageConverter throws ArgumentNullException

Open FixBo opened this issue 7 years ago • 4 comments

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 avatar Jan 23 '19 09:01 FixBo

@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?

danmoseley avatar Jan 23 '19 23:01 danmoseley

.NET Core 3.0 preview on Windows 10.

FixBo avatar Jan 24 '19 02:01 FixBo

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.

saucecontrol avatar Mar 28 '19 09:03 saucecontrol

I believe this is the same as https://github.com/dotnet/corefx/issues/36525

ericstj avatar Apr 15 '19 13:04 ericstj