I have multiple buttons, each having a 32x32 pixels PNG image. The strange thing is, that both buttons show different sizes (Yes, I triple checked that icons are really 32x32!).
The two images probably have different DPIs.
To follow up on SLaks answer: To use the Pixel dimensions of the Image regardless of the DPI you can bind the Width and Height to the PixelWidth and PixelHeight of the Source like this
<Button Name="toggleDetails" ToolTip="Details for Item" Click="toggleDetails_Click">
<Image Source="Icons/maximize.png"
Stretch="None"
Width="{Binding RelativeSource={RelativeSource Self}, Path=Source.PixelWidth}"
Height="{Binding RelativeSource={RelativeSource Self}, Path=Source.PixelHeight}"/>
</Button>
If you have set Stretch="None"
for the Image
, and it still looks larger/smaller/blurry, then it's probably because of the DPI mismatch.
For example, PNG files store DPI. Windows has a particular DPI. Check your system DPI and check the PNG DPI.
In Photoshop you can go to Image -> Image Size
and it will display the dots/inch box. You can also use it to change the DPI. Make sure you disable Resample Image
checkbox so that you only alter the DPI. You need to use the Save for Web
dialog for saving that change because the normal Save As
won't save that information.
In my case, I had a PNG file with size of 24x24, and a DPI 72.009 and my system is at the default DPI. The picture looked larger and blurrier, now it's fine after adjusting the PNG DPI from 72.009 to 72 with Photoshop and using the Save for Web
.