Вопрос

I am working on Windows Phone 8 app.

I have a path to image - /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.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.

Это было полезно?

Решение

If you want the get the size of an image, you need to load it in a 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 с атрибуция
Не связан с StackOverflow
scroll top