I am trying to convert an image to an icon. My function is:
private Icon GenerateIcon(int width, int height)
{
using (Bitmap icon = _backingImage.GetThumbnailImage(width, height, () => false, System.IntPtr.Zero) as Bitmap)
using(MemoryStream imgStream = new MemoryStream())
{
icon.Save(imgStream, System.Drawing.Imaging.ImageFormat.Icon);
return new Icon(imgStream);
}
}
But when the programme calls the method, it throws an ArgumentNullException("encoder")
where I'm calling icon.Save
.
I find this odd because I'm not passing in an encoder, I want the framework to figure out what the encoder should be, which is why I'm passing in an ImageFormat
.
Is it that there aren't any encoders for ImageFormat.Icon
, or is there something I'm doing wrong?