【问题标题】:WPF Images same width/height/dpi but different dispayWPF 图像相同的宽度/高度/dpi 但显示不同
【发布时间】:2018-03-22 18:49:46
【问题描述】:

我从一张较大的图片中剪下了两张图片。两个剪切图像都是 300x148 并且有 96 dpi。

我这样显示它们:

<Image Source="{Binding Image1, Converter={StaticResource imageConverter}}" />
<Image Source="{Binding Image2, Converter={StaticResource imageConverter}}" />

问题是我在视觉上看到了高度的差异。更奇怪的是,当我交换它们时:

<Image Source="{Binding Image2, Converter={StaticResource imageConverter}}" />
<Image Source="{Binding Image1, Converter={StaticResource imageConverter}}" />

高度差发生变化但仍然存在。

我把一些日志记录到ImageCoverter 来记录返回值,宽度/高度/dpi 值没有区别。

我没有任何影响图像的样式。

还有其他我应该考虑的领域吗?

编辑 这就是我创建 300x148 图像的方式。我通过裁剪的图像和宽度:

public static Bitmap Scale(Bitmap image, double width)
{
    double ratio = width / image.Width;
    var newWidth = (int)(image.Width * ratio);
    var newHeight = (int)(image.Height * ratio);

    var scaledImage = new Bitmap(newWidth, newHeight);

    using (var graphics = Graphics.FromImage(scaledImage))
    {
        graphics.DrawImage(image, 0, 0, newWidth, newHeight);
    }

    return scaledImage;
}

【问题讨论】:

  • 尝试设置Stretch="None",并向我们展示您创建裁剪图像的代码。
  • 我尝试使用它,没有任何反应
  • @N.Zukowski,尝试使用 Image1 作为两者的来源并观察会发生什么
  • @ASh 我已经做到了,两个相同的图像在高度上没有区别。所以我认为这两个不同的图像在某种程度上确实有不同的高度,但怎么会发生呢?
  • 您只想将整个图像缩放到不同的像素宽度和高度,而不是从较大的图像中裁剪出来,对吧?

标签: wpf image wpf-controls


【解决方案1】:

Image 是一个显示图片的控件。 不能只设置图像控件的高度和宽度吗?

<Image Height="100" Width="100" 

【讨论】:

  • 不要把这个写成问题。相反,显示 XAML 的外观。
猜你喜欢
  • 1970-01-01
  • 2018-12-29
  • 2021-08-25
  • 2017-09-18
  • 1970-01-01
  • 2015-03-10
  • 1970-01-01
  • 2010-10-29
  • 2016-05-13
相关资源
最近更新 更多