Question

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.

Was it helpful?

Solution

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
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top