简体   繁体   English

在运行时获取图像的宽度和高度-WP8

[英]Get width and height of image at run time - WP8

I am working on Windows Phone 8 app. 我正在使用Windows Phone 8应用程序。

I have a path to image - /Data/Images/image1.png . 我有一个图像的路径-/ /Data/Images/image1.png I am able to display this image on screen, but i want to change the width and height of the image before its rendered. 我可以在屏幕上显示此图像,但是我想在渲染之前更改图像的宽度和高度。

This is how i am displaying the image in webbrowser control 这就是我在网络webbrowser control显示图像的方式

webbrowser.Append("<img src=""+path+ width=\"250\" height=\"250\" style=\"vertical-align:middle\" alt=\"\"></img>"/>"

Here i am setting width and height as 250x250 but i want to change that height and width as some images are not looking good. 在这里,我将宽度和高度设置为250x250但由于某些图像效果不好,我想更改该高度和宽度。

If you want the get the size of an image, you need to load it in a BitmapImage : 如果要获取图像的大小,则需要将其加载到BitmapImage

int width = 0;
int height = 0;
using (var stream = Application.GetResourceStream(new Uri("Assets/test.jpg", UriKind.Relative)).Stream)
{
    var bmpi = new BitmapImage();
    bmpi.SetSource(stream);
    bmpi.CreateOptions = BitmapCreateOptions.None;
    width = bmpi.PixelWidth;
    height = bmpi.PixelHeight;
    bmpi = null; // Avoids memory leaks
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM