dimensions - Windows Store load URL image and get size -


i need load 8 images image or bitmapimage elements in c# windows store (windows rt) app, , need find dimensions (even before being displayed). can download images, can't figure out how size (size zero). reason size 0 bitmap image has not loaded, can't figure out how wait till image loaded, catch function indicates image has loaded.

here key code, imageopened or imagefailed never called:

bm.imageopened += bm_imageopened; bm.imagefailed += bm_imagefailed; bm = new bitmapimage(new uri(arbitraryimageurithatkeepschanging, urikind.absolute)); image.imagefailed += image_imagefailed; image.imageopened += image_imageopened; image.source = new bitmapimage(new uri(arbitraryimageurithatkeepschanging,                 urikind.absolute));  /* .. @ point image still has not been loaded,  can't find dimensions or if failed or not, , functions catch  image opened , failed never called..*/ 

all need load images external web site, , find dimensions, before displaying images.

you use dummy-imageelement invisible preload image.

in xaml:

<image name="dummyimage" visibility="collapsed"/> 

code behind:

bitmapimage btm = new bitmapimage(new uri("http://anyurl.com/foo.jpg")); btm.downloadprogress += btm_downloadprogress; dummyimage.source = btm;  private void btm_downloadprogress(object sender, downloadprogresseventargs e)     {         if (e.progress == 100)         {             int width = ((bitmapimage)sender).pixelwidth;         }     } 

you should able use either downloadprogress or imageloaded event.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -