Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top