How to make the image not stretched?

[deleted image imgur]

The icon on the left is the result of this code:

    <Button Height="23" HorizontalAlignment="Left" Margin="12,276,0,0" Name="button1" VerticalAlignment="Top" Width="75">
        <StackPanel Orientation="Horizontal">
            <Image Source="Resources/add.png" Stretch="None" />
            <TextBlock Margin="5,0,0,0" Text="Add" />
        </StackPanel>
    </Button>

On the right is the original image placed next to it using Photoshop. It seems that the one added through the code is stretched by a pixel, causing some distortion. How to prevent this?

+6
source share
8 answers

This is fixed for me:

The root element (ie, in the main window), add this property: UseLayoutRounding="True".

credit

0
source

Stretch="None"should do just that. If there is a difference in the way the image is displayed, which may be due to the fact that the pixels end โ€œon the edgeโ€.

SnapsToDevicePixels ="True", .

+8

RenderOptions.BitmapScalingMode="NearestNeighbor".

:

+4

, , WPF DPI PNG , - , 96 ( 72, - Mac).

+3

Stretch = None

<ImageBrush ImageSource="rtgEnhanced.png" AlignmentX="Left" AlignmentY="Bottom" Stretch="None"></ImageBrush>
+3

NearestNeighbor . Linear, , .

+1

, . , , 48 , :

<Image Source="myImage.png" Height="48" UseLayoutRounding="True"/>
+1

PNG -, pHYs, . DPI, . DPI DPI , WPF, "" . ( ) , , .

"" , pHYs PNG.

You can use a tool like TweakPNG to check and remove pHY values.

Alternatively, you can simply save your images using the correct DPI encoded in them, or nothing at all, assuming your image editing software supports this.

+1
source

All Articles