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

Goo*_*ofy 0 c# silverlight image windows-phone windows-phone-8

我正在使用Windows Phone 8应用程序.

我有一条通往图像的道路 - /Data/Images/image1.png.我能够在屏幕上显示此图像,但我想在渲染之前更改图像的宽度和高度.

这就是我在显示图像的方式 webbrowser control

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

在这里我设置宽度和高度,250x250但我想改变高度和宽度,因为一些图像不好看.

Oli*_*yen 5

如果您想获得图像的大小,则需要将其加载到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
}
Run Code Online (Sandbox Code Playgroud)