tags:

views:

573

answers:

1

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.)

+2  A: 

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.

Nir
This is probably right, although it seems weird that there is no synchronous download (or at least a not easily discoverable one). I will be sure to mark this as accepted after I test it, which will be once my homework gets under control :P.
Domenic