I am creating images in various formats in WPF using BitmapEncoder. For example, to create a png image from a FrameworkElement, i am using the following code,
BitmapEncoder imgEncoder = new PngBitmapEncoder();
RenderTargetBitmap renderBitmap = new RenderTargetBitmap(32, 32, 96d, 96d, PixelFormats.Pbgra32);
renderBitmap.Render(controlToConvert);
imgEncoder.Frames.Add(BitmapFrame.Create(renderBitmap));
I like to create an .ico file in the same way. But I cannot find any IconBitmapEncoder in WPF. Is there any other way to do it?
Regards,
Jawahar
There is none.
I have tried to save images as *.ico in the past and other .NET classes did not really help (if i remember correctly they could only decode, not encode; but maybe i just did something wrong). *.ico can be a container for PNG images (there may be backwards compatibility issues though), so you can stick a full PNG in there with the right headers which could be found on wikipedia.
Example implementation: