【问题标题】:Image renders differently depending on position图像根据位置呈现不同
【发布时间】:2011-04-12 04:44:07
【问题描述】:

我有一个显示按钮列表的 ItemsControl。每个按钮都有一张图片作为其内容 (png),但每行的图片看起来略有不同。

下图是我看到的放大版:

这里是 xaml:

<ItemsControl ItemsSource="{Binding Items}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <StackPanel   Orientation="Horizontal">
                <TextBlock Name="tb1">hello</TextBlock>
                <Button Height="{Binding ElementName=tb1, Path=ActualHeight}" Padding="0,-3,-3,-3" BorderBrush="Transparent" Background="Transparent" >
                    <Image Stretch="Fill"  Source="stock_standard_filter.png" Margin="0">
                    </Image>
                </Button>
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

我有一个similar issue previously 并且能够使用SnapsToDevicePixels="True" 解决它,但是这次该解决方案不起作用。我也试过UseLayoutRounding="True"RenderOptions.EdgeMode="Aliased"

【问题讨论】:

  • 如果您尝试 Stretch="None" 会发生什么?
  • @blindmeis:还是渲染不一样,更糟糕的是图片太大了。

标签: wpf image rendering


【解决方案1】:

按钮的高度是绑定的,因此图像将被拉伸以填充按钮。因为 WPF 使用双精度数(1/96 英寸单位),所以必然会有一些舍入。当您在 StackPanel 上使用 SnapsToDevicePixels 和布局舍入时可能会有所帮助,但只要您拉伸图像,它就会变得模糊。

我最好的猜测是设置“Stretch to None”并尝试使用 SnapsToDevicePixels 和布局舍入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-15
    • 2013-10-09
    • 1970-01-01
    • 2019-12-07
    • 2021-10-04
    • 1970-01-01
    • 2022-06-10
    • 2014-04-04
    相关资源
    最近更新 更多