.net - How to retrieve the largest available image from an icon file, using C# -


i need retrieve largest bitmap image icon file (.ico) contains several sizes of image.

in icon editor can see there several images in icon file, namely 16x16px, 24x24, 32x32, 48x48 , 256x256.

however following lines of code miss 256x256 image 1 want:

var iconobj = new system.drawing.icon(tempfilename); //iconobj 32x32 //get 'default' size image: var image1 = iconobj.tobitmap(); //retrieved image 32x32 //get largest image 1024x1024: var image2 = new system.drawing.icon(iconobj, new system.drawing.size(1024, 1024)).tobitmap(); //retrieved image 48x48 

how largest image available (or specific size) icon file?

looks, microsoft has bug in implementation, not takes in consideration icon format "specifies image width in pixels. can number between 0 , 255. value 0 means image width 256 pixels". so, maximum size of returned icon icon(string, size) can 128x128. found workaround: when specify -1,-1 height , width, result 256x256 icon (am not sure order of images in ico file, specification ordering size not provided, use in project)

using system; using system.drawing;  static class program {      static void main()     {         icon image2 = new system.drawing.icon("softskin-series-folder-folder-bd-files.ico",-1,-1);         console.writeline( "height={0} width={1}",image2.height,image2.width    );       } } 

Comments