【问题标题】:Image's ActualHeight and ActualWidth properties are different from DecodePixelHeight/WidthImage 的 ActualHeight 和 ActualWidth 属性与 DecodePixelHeight/Width 不同
【发布时间】:2014-07-28 13:34:45
【问题描述】:

我正在开发一个 Windows phone 8 应用程序,我需要在其中显示一些图像。我使用了一个图像控件(未指定尺寸)并传递了一个 ImageUri(指向本地存储),并在转换器中返回了一个 BitmapImage,每个 DecodePixelHeight/Width 设置为 300。除了在诺基亚 Lumia 920 手机(我在 Lumia 520、Lumia 820、HTC 8S 和 Lumia 920 中测试过)外,它工作正常。在 920 中进行测试时,在 image_loaded 事件中,即使图像源的 DecodePixelheight/Width 每个显示为 300,图像的 ActualHeight/Width 每个也为 480。为什么会这样? (隔离存储中的图像尺寸也是 300x300)。

这是我的转换器代码:

    BitmapImage image = new BitmapImage();

    image.DecodePixelType = DecodePixelType.Logical;
    image.CreateOptions = BitmapCreateOptions.BackgroundCreation;
    image.CreateOptions = BitmapCreateOptions.DelayCreation;
    image.DecodePixelHeight = 300;
    image.DecodePixelWidth = 300;
    using (var stream = LoadFile(path.ToString()))
    {
         if (stream != null)
         {
             image.SetSource(stream);
         }
    }
    return image;

我从两个原始屏幕截图中裁剪了相同的区域。

【问题讨论】:

  • 如果您不希望图像重新缩放以更好地适应 Lumia 920 等高分辨率屏幕,请使用 DecodePixelType.Physical。

标签: c# image windows-phone-8


【解决方案1】:

发生这种情况是因为 DecodePixelHeight/Width 只会使图像被解码为该大小。实际呈现的尺寸取决于其他变量(宽度和高度)。

Lumia 920 结果不同的事实是因为该设备具有 WXGA (768x1280) 分辨率,而所有其他设备具有 WVGA 分辨率 (480x800)。

这会导致图像重新缩放以适应 WXGA 手机分辨率的宽度/高度。

我不太清楚你想要完成什么,但我猜你正在将从该函数返回的图像分配给某种控制。我的建议是你给那个控件一个固定的宽度和高度,看看效果如何。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多