如何获取图片网址的大小?
我试图使用:
var img = new BitmapImage(new Uri(url));
img.ImageOpened += (a, d) =>
{
Debug.WriteLine("Width: {0}, Height: {1}", img.PixelWidth, img.PixelHeight);
};
Image1.Source = img;
但它没有解决我的问题。
答案 0 :(得分:2)
您应该处理ImageOpened
控件的Image
事件:
<Image x:Name="Image1" ImageOpened="Image1_OnImageOpened" ></Image>
并获取处理程序中的宽度和高度
private void Image1_OnImageOpened(object sender, RoutedEventArgs e)
{
var width =(Image1.Source as BitmapImage).PixelWidth;
var height =(Image1.Source as BitmapImage).PixelHeight;
}