【问题标题】:WP7 set Image component height/width to BitmapImage height/widthWP7 将 Image 组件高度/宽度设置为 BitmapImage 高度/宽度
【发布时间】:2011-08-06 11:20:33
【问题描述】:

我正在尝试将 Image 组件源设置为 BitmapImage:

然而,

Uri newUri = new Uri("images/" + filename, UriKind.Relative);
Image newImage = new Image();
BitmapImage bmp = new BitmapImage(newUri);
newImage.Source = bmp;

但是,如果图像小于屏幕,则会缩放以填充它。

我尝试设置宽度和高度如下:

  newImage.Height = bmp.PixelHeight;
   newImage.Width = bmp.PixelWidth;

但 BitmapImage 的宽度和高度返回零值。我想这是因为它还没有“加载”?

如何强制它为我提供正确的值或至少强制 Image 组件“换行”只适合位图的大小。

我所有的图片都是适合屏幕的像素尺寸。

谢谢

【问题讨论】:

    标签: image windows-phone-7 size bitmapimage


    【解决方案1】:

    在实际加载之前,位图不知道它是 PixelHeight 和 PixelWidth,这就是您得到零的原因。但是,与其尝试手动设置宽度和高度,只需将 Stretch 属性设置为 None,图像将始终保持其原始大小。

    注意:如果您使用像素完美的图像作为布局的一部分,请确保它能够应对方向更改为横向:)

    【讨论】:

    • 感谢您的信息,实际上,我的程序将始终强制横向布局,因此无需处理定向机会。再次感谢。我这星期一试试。
    • 刚刚使用 Stretch 进行了测试,效果很好,谢谢。已接受答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    • 2020-11-08
    • 2020-06-11
    • 1970-01-01
    相关资源
    最近更新 更多