我正在开发Windows Phone 8应用程序。
我有一张图片路径 - /Data/Images/image1.png
。我可以在屏幕上显示此图像,但我想在渲染之前更改图像的宽度和高度。
这是我在webbrowser control
webbrowser.Append("<img src=""+path+ width=\"250\" height=\"250\" style=\"vertical-align:middle\" alt=\"\"></img>"/>"
这里我将宽度和高度设置为250x250
,但我想更改高度和宽度,因为有些图像效果不佳。
答案 0 :(得分: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
}