Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sizing and working with ICO files in WPF/C#

In an application I'm working on there are Images (part of System.Windows.Media.Imaging) being created dynamically in the code-behind of a XAML page and getting added to the window. I'm using ICO files, which contain various sizes and bit depths. The size I want is 96x96 @ 32 bit. The code automatically selects the largest size (256x256 @ 32 bit).

I'm setting the Image.Source property as follows:

image.Source = new BitmapImage(new Uri("pack://application:,,,/Resources/Images/Application.ico"));

Now, by searching around I've found the Icon (part of System.Drawing) which will allow me to set a string path and size, but this is a part of an entirely different library.

new Icon("pack://application:,,,/Resources/Images/Inquiry.ico",96,96);

Any idea how I can make my Image's size property a bit more manageable? Thank you!

EDIT: Convert System.Drawing.Icon to System.Media.ImageSource
This post gets the image to appear smaller, however, it doesn't matter if I set the Icon to 96x96 or 128x128, it doesn't actually change the displayed image's size. I'm assuming it's going to some default value that is different that the System.Windows.Media.Imaging default.

EDIT to the EDIT: Weird keeps getting weirder. When I display through the original method, it's definitely displaying the image as 256x256. However, when I use the conversion method described in the link, while the sizes change, they are significantly scaled down (i.e. 256x256 looks closer to 48x48).

like image 210
Wally Young Avatar asked Oct 05 '11 21:10

Wally Young


People also ask

What size should my ICO file be?

The . ico file format is required. For Classic Mode, the full set is 16x16, 24x24, 32x32, 48x48 and 64x64.

How add ICO to WPF?

To add an icon to a project, right click on the project name in Solution Explorer. Right click will open Add Items menu. Select Add >> New Item. Now on Installed Templates, select Icon File (see Figure 1) and click Add.

How do I reduce the size of my ICO?

To resize desktop icons, right-click (or press and hold) the desktop, point to View, then select Large icons, Medium icons, or Small icons.

Are ICO files scalable?

Multiple sizes of the ICO images allow icons to be scaled appropriately. On Windows OS, all the icons are ICO format files. Since the launch of this format by Microsoft, it has been developed a lot. Latest ICO images can be of 256 x 256 pixels and contain 24 bits of colors and 8 bits of transparency.


1 Answers

Try the markup extension that is posted in this answer to another SO question. Note the use of BitmapDecoder to get the required frame from the Ico file.

like image 89
Olly Avatar answered Oct 10 '22 02:10

Olly