Question

I'm working in metro applications.

And I'm using BitmapImage, where since the constructor I set the Uri, but I realized that all the time PixelWidth and PixelHeight returns 0 (I've verified also that the Uri is correct).

I can't find another class which returns me those properties. I was thinking if there's a way to get those data through a byte array or something like that. What do you think?

Était-ce utile?

La solution

Check the CacheOption property and set to BitmapCacheOption.None. You can also try convert to a WriteableBitmap. If what I said is not true, sorry, because I can not test on. Xaml (wpf only) xD

Autres conseils

BitmapImage returns 0 for PixelWidth and PixelHeight if the image isn't loaded. The image is only loaded when it's actually used, for example, assigned to Image.Source and displayed. That's... problematic. Using BitmapCacheOption.None doesn't help, it only worked on WP7.

The right solution is to use BitmapDecoder:

var stream = await storageFile.OpenReadAsync();
var decoder = await BitmapDecoder.CreateAsync(stream);
var size = new BitmapSize { Width = decoder.PixelWidth, Height = decoder.PixelHeight };

Found this solution on MSDN forums.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top