In WPF, you can do something like this:
Stream iconStream = new FileStream ( @"C:\yourfilename.ico", FileMode.Open ); IconBitmapDecoder decoder = new IconBitmapDecoder ( iconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None ); // loop through images inside the file foreach ( var item in decoder.Frames ) { //Do whatever you want to do with the single images inside the file this.panel.Children.Add ( new Image () { Source = item } ); } // or just get exactly the 4th image: var frame = decoder.Frames[3]; // save file as PNG BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(frame); using ( Stream saveStream = new FileStream ( @"C:\target.png", FileMode.Create )) { encoder.Save( saveStream ); }
Stephan bauer
source share