1

Using C# or VB.NET, and under Windows Forms, which for this I'm using WPF library classes to make it easier, I would like to load a .ico file, then I will add a new frame to the icon object, and save the icon object with the new frames added (preferably as a System.Drawing.Icon object, otherwise, save it as a new .ico file), simple as that.

For iterating the frames of an icon I'm using the IconBitmapDecoder class, I'm following this example. However, the IconBitmapDecoder.Frames is a ReadOnlycollection, so I'm stuck at this point, I don't know which class I need to use to create an icon, adding the frames that I obtained using the IconBitmapDecoder class, plus the additional frames that I want to add.

If necessary, bitmap frames (a System.Windows.Media.Imaging.BitmapFrame or BitmapSource object) can be converted to a System.Drawing.Bitmap object by following this example.

Please note that I'm very inexperienced using WPF classes.

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
  • 1
    See this CodeProject article: [IconLib - Icons Unfolded](https://www.codeproject.com/Articles/16178/IconLib-Icons-Unfolded-MultiIcon-and-Windows-Vista). The schema presented there is one interesting thing in itself. Also mirrored and updated in this GitHub repository: [IconLib](https://github.com/Jamedjo/IconLib). Also, Hans Passant's take on this: [How to convert an image to an icon without losing transparency?](https://stackoverflow.com/questions/21387391/how-to-convert-an-image-to-an-icon-without-losing-transparency?answertab=active#tab-top). It exposes the Icon's *internals* (in code). – Jimi Nov 11 '18 at 05:26
  • 1
    As you have probably noticed, there's no Encoder for the Icon format, only the Decoder (and if you try to save a Bitmap as Icon using the `System.Drawing` assemblies format, you'll get a PNG file -> GDI+ doesn't support it). But you might be interested in this: [A High-Quality IconBitmapEncoder for WPF](https://www.codeproject.com/Articles/687057/A-High-Quality-IconBitmapEncoder-for-WPF) – Jimi Nov 11 '18 at 05:26
  • 1
    Also interesting (I think): [Creating and Saving a Multiple-Frame Image - MSDN](https://learn.microsoft.com/en-us/windows/desktop/gdiplus/-gdiplus-creating-and-saving-a-multiple-frame-image-use) – Jimi Nov 11 '18 at 05:36
  • 1
    The article from CodeProject looks great, I will give it a try. Thank you as always @Jimi. Note that the source-code included in the article is flagged as obsolete by the author, who has updated it and moved to GitHub: https://github.com/HerbertLausmann/HL.IconPro – ElektroStudios Nov 11 '18 at 05:47
  • 1
    I'm adding one (partially related) note on this: if you reference a WPF assembly in your WinForms application which is not DPIAware, it will, most probaly, become automatically DPIAware (SystemAware). This can produce (un)predictable differences in the Forms rendering (and size). See these notes on the matter: [DPI Awareness - Unaware in one Release, System Aware in the Other](https://stackoverflow.com/questions/50239138/dpi-awareness-unaware-in-one-release-system-aware-in-the-other?answertab=active#tab-top) – Jimi Nov 11 '18 at 05:58
  • Dunno if this can help... I answered a question like this a while ago: [Combine System.Drawing.Bitmap\[\] -> Icon](https://stackoverflow.com/q/54801185/395685) – Nyerguds Apr 20 '20 at 14:23

0 Answers0