DragonWalsh

Hello All,

I'm currently using PNG's within my WPF application, but upon changing from 96 DPI to 120, 144, etc...the images within my application are scaled. For example, 32x32 unit images are scaled to 40x40.

What I would like to do is provide high resolution versions of these images to be replaced when the DPI is set to higher than 96, such as the way Icons work with the OS.

In specific, I want to replace my PNG images with .ico images and then within the ICO provide a 32x32 as well as a 40x40 sample of the image. Then, when the user sets his/her DPI to 120, I'd like it to pull the 40x40 image, rather than scaling the 32x32 image to 40x40.

I've poured through the documentation and have discovered the OS does this "automagically" for the Application Icon with respect to the task bar, windows explorer, etc...but have found no documentation on how to do this within the application for other images such as Toolbar Icons.

I tried just substituting the .png for an .ico, but as indicated within the documentation, the Image element just selects the first frame within an image where an image format supports more than one frame.

So does anyone know of an easy way to select the frame within an ICO based on

A) DPI
B) color depth (32bit, 8bit, 4bit)

It just seems like there is/should be an easy way to do this. I'm hoping I'm just overlooking the easy solution.

Thanks!


Re: Windows Presentation Foundation (WPF) WPF & DPI dependant Icons?

Drew Marsh

Why not use scalable vector based assets instead of bitmap images Those will scale infinitely in all resolutions and DPIs.

HTH,
Drew





Re: Windows Presentation Foundation (WPF) WPF & DPI dependant Icons?

Ryan Lamansky

If vector-based images are not an option, simply use higher-resolution PNG images. WPF takes care of downsampling automatically. There is a slight expense in disk space and RAM for this, but it's far easier to do than any other option.

-Ryan / Kardax





Re: Windows Presentation Foundation (WPF) WPF & DPI dependant Icons?

DragonWalsh

Ryan, Thanks for your response.

The problem is that just using a higher resolution image isnt always the best option. When WPF downsamples the higher resolution image much of the details become cluttered, there's usually not enough contrast, etc...It's often better to provide an 'alternate' lower resolution version.

Although using a higher resolution image would be a viable option in the 32x32+ range, where there is plenty of room for data to begin with, it's not a viable option in the 24x24, 16x16, 14x14, or 10x10 ranges. For these, it would be much better to be able to swap in a lower resolution, different image - with a higher contrast and more pronounced details, when using a lower resolution.

Or another way to look at it, I'd rather not have the images I made to look good at 14x14 and 16x16 be scaled up to 24x24. I'd much rather put in an image that's appropriate at 24x24.

Any other ideas




Re: Windows Presentation Foundation (WPF) WPF & DPI dependant Icons?

Drew Marsh

Well, nothing does this for you out of the box. You can play with SystemParameters.IconGridWidth which should tell you the current width of a large icon on the system. From there maybe you can write a value converter that takes the static image name as the converter parameter and binds to IconGridWidth and then returns the correct source for the image using IconBitmapDecoder based on the current value. Something like:

Code Snippet
<Image Width="{x:Static SystemParameters.IconGridWidth}" Height="{x:Static SystemParameters.IconGridHeight}" Source="{Binding Source={x:Static SystemParameters.IconGridWidth}, Converter=myns:MyConverter, ConverterParameter=myIcon.ico" />

If you needed to bind the source as well, then you could use a multi-binding instead:

Code Snippet

<Image Width="{x:Static SystemParameters.IconGridWidth}" Height="{x:Static SystemParameters.IconGridHeight}">

<Image.Source>

<MultiBinding Converter="myns:MyConverter">

<Binding Source="{x:Static SystemParameters.IconGridWidth}" />

<Binding Path="MyIconSourceProperty" />

</MultiBinding>

</Image.Source>

</Image>

HTH,
Drew





Re: Windows Presentation Foundation (WPF) WPF & DPI dependant Icons?

Ryan Lamansky / Kardax

Bear in mind that though 96 and 120 are "default" DPIs, the user can choose any DPI they want and it's a near certainty this will happen as higher DPI monitors come to market.

Your program must be able to handle this, ideally by selecting the "best" image for each DPI.

-Ryan / Kardax