Image in WPF getting Blurry

前端 未结 7 838
慢半拍i
慢半拍i 2020-11-30 03:58

I am developing an application in WPF using C#. I am putting Images in a WrapPanel and showing inside a Grid with one more Border and using images in Buttons also. Problem i

相关标签:
7条回答
  • 2020-11-30 04:32

    This works for me

    <Image Source="/LoginPanel;component/Icons/icoLogin.ico"
           RenderOptions.BitmapScalingMode="NearestNeighbor"</Image>
    

    Set RenderOptions.BitmapScalingMode="NearestNeighbor" for each image. Alternatively see this question here on StackOverflow.

    Edit:
    Here is my sample code

    <Window x:Class="MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="661">
        <WrapPanel>
            <Button VerticalAlignment="Center">
                <Image Source="/WpfApplication1;component/icoChip32x32.ico"
                   RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="None"></Image>
            </Button>
            <Button VerticalAlignment="Center">
                <Image Source="/WpfApplication1;component/icoChip32x32.ico"
                       RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="None"></Image>
            </Button>
    
            <Button VerticalAlignment="Center">
                <Image Source="/WpfApplication1;component/Presentation-Edit.png"
                   RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="None"></Image>
            </Button>
            <Button VerticalAlignment="Center">
                <Image Source="/WpfApplication1;component/Presentation-Edit.png"
                       RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="None"></Image>
            </Button>
        </WrapPanel>
    </Window>
    

    And this is my result:
    ...and this is my result

    0 讨论(0)
提交回复
热议问题