【问题标题】:Get image dimension from url?从网址获取图像尺寸?
【发布时间】:2016-01-26 09:40:48
【问题描述】:

如何获取图片url的大小?

我尝试使用:

var img = new BitmapImage(new Uri(url));
img.ImageOpened += (a, d) =>
{
   Debug.WriteLine("Width: {0}, Height: {1}", img.PixelWidth, img.PixelHeight);
};
Image1.Source = img;

但这并没有解决我的问题。

【问题讨论】:

  • 你试过img.Widthimg.Height吗?
  • 是的,但是 BitmapImage 没有 Width 和 Height 属性,只有 PixelWidth、PixelHeight、DecodePixelHeight 和 DecodePixelWidth。
  • 嗯...可能是因为是WP的BitmapImage...
  • 你能详细说明“它不能解决我的问题”是什么意思吗?尺寸错误或为空?
  • 抱歉不准确。是的,它是 WinRT BitmapImage。我得到一个空值

标签: c# windows-runtime windows-phone-8.1 windows-8.1


【解决方案1】:

您应该改为处理Image 控件的ImageOpened 事件:

<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;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-02
    • 2011-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多