문제

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