2

I've managed to get an image's width/height if its stored in my computer with the following code:(Fullpath is the file's full location)

        var bitmapFrame = BitmapFrame.Create(new Uri(FullPath), BitmapCreateOptions.DelayCreation, BitmapCacheOption.None);
        var width = bitmapFrame.PixelWidth;
        var height = bitmapFrame.PixelHeight;

But the second I try to change the FullPath to an internet image (such as http://www.interweb.in/attachments/pc-wallpapers/16187d1222942178-nature-wallpaper-nature-summer-wallpaper.jpg) the width and height will not determine the real values needed and will just remain with the value of "1".

I've been sitting for a few hours here trying to figure out what went wrong and working a way around it but without success. Thank you very much in advance!

Oranges
  • 193
  • 1
  • 2
  • 16

1 Answers1

1

Try this. For net Uri the ImageSource will download the image asynchronously, to avoid blocking.

    var bitmapFrame = BitmapFrame.Create(new Uri(FullPath), BitmapCreateOptions.None, BitmapCacheOption.None);
    if(bitmapFrame.IsDownloading)
    {
        bitmapFrame.DownloadCompleted += (e, arg) =>{
            var width = bitmapFrame.PixelWidth;
            var height = bitmapFrame.PixelHeight;

        }
    }

You want to wait for the DownloadCompleted event.

Aron
  • 15,464
  • 3
  • 31
  • 64
  • I've tried to copy your suggestion (only thing I changed was the parameter name from e to t because I'm testing it on a button click) but the values are still 1. – Oranges Oct 29 '13 at 09:20
  • I've found the problem, it needs to be BitmapCreateOptions.None instead of BitmapCreateOptions.DelayCreation . Thank you very much :)! – Oranges Oct 29 '13 at 18:21