문제

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?

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top