WP7将图像组件高度/宽度设置为BitmapImage高度/宽度
我正在尝试将图像组件源设置为 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 返回宽度和高度的零值。我认为这是因为它还没有“加载”?
我如何强制它给我正确的值或至少强制图像组件“换行”仅适合位图的大小。
我的所有图像都是适合屏幕的像素完美尺寸。
谢谢
I am trying to set an Image component source to a BitmapImage:
However, the
Uri newUri = new Uri("images/" + filename, UriKind.Relative);
Image newImage = new Image();
BitmapImage bmp = new BitmapImage(newUri);
newImage.Source = bmp;
However, if the image is smaller than the screen is is scaled to fill it.
I have tried setting the width and height as follows:
newImage.Height = bmp.PixelHeight;
newImage.Width = bmp.PixelWidth;
but the BitmapImage returns zero values for the width and height. I presume this is because it hasn't "loaded" yet?
How do I force this to give me the right values or atleast force the Image component to "wrap" only fit itself to the size of the bitmap.
All my images are pixel perfect sizes for the screen.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
位图在实际加载之前并不知道它是 PixelHeight 和 PixelWidth,这就是为什么你得到零。但是,无需尝试手动设置宽度和高度,只需将 Stretch 属性设置为 None 即可,图像将始终保持其原始大小。
注意:如果您使用像素完美图像作为布局的一部分,请确保它能够应对横向方向的变化:)
The Bitmap doesn't know it's PixelHeight and PixelWidth until it's actually been loaded, which is why you're getting zero. However, rather than trying to manually set the Width and Height, simply set the Stretch property to None and the image will always be it's original size.
NOTE: If you're using pixel perfect images as part of your layout, make sure it copes with the orientation change to landscape :)