Edward Brey
Edward Brey

Reputation: 41638

WPF: Use a specific icon image in an Image element

How do I get a System.Windows.Controls.Image to use an image of a specified resolution and color depth from a .ico resource?

Upvotes: 3

Views: 1074

Answers (1)

Edward Brey
Edward Brey

Reputation: 41638

Create a BitmapFrame and use its Decoder. For example, to access a 48x48, 32-bit image:

BitmapFrame icon = BitmapFrame.Create(new Uri("pack://application:,,,/Resources/Icon.ico", UriKind.Absolute));
BitmapFrame image = icon.Decoder.Frames.First(f => f.PixelHeight == 48 && f.Format.BitsPerPixel == 32);

Upvotes: 4

Related Questions