Reputation: 112817
I don't understand...
BitmapImage img = new BitmapImage(myUri);
Console.WriteLine("Width: {0}, Height: {1}", img.Width, img.Height);
Output: "Width: 1, Height: 1".
I've tried PixelWidth/PixelHeight, I've tried manually creating it with BeginInit
/EndInit
and also setting PreservePixelFormat
... nothing works.
(Except, even wierder: this is all part of a process where the user clicks a button and some images get downloaded. Well, the second time that button is clicked, it does have non-1 width/height.)
Upvotes: 4
Views: 2502
Reputation: 29594
The first time the user clicks the button the bitmap hasn't been downloaded yet - so anything you do with it will cause garbage results (except displaying it, because the Image control knows how to handle this).
You can handle the BitmapImage.DownloadCompleted event to know when the bitmap is available.
Upvotes: 4