简体   繁体   中英

Silverlight image loading problems

I simply cannot load Silverlight images synchronously. ImageOpened is all well and good but it doesn't really help me if if I have 20 textures to load BEFORE the app is allowed to execute! You cannot use threads as it causes multiple cross domain / cross thread exceptions. I have solved it but I am v curious as to how anyone else has tackled this.

My requirement is to load a jpeg / png / whatever into a pixel array, as i say, asynchronous options are a no go as I NEED the pixels before I start rendering.

Help!

you didn't say, from where you load a jpeg / png / whatever. If from resource, you can try to load first to BitmapImage, but not by UriSource property. Just use a method SetSource() - for me it loads the image immediately.

For example:

using System.Windows.Media.Imaging;
using System.Windows.Resources;


BitmapImage bmp = new BitmapImage();
Uri uri = new Uri("/SilverlightApp1;component/Resources/foto.jpg", UriKind.Relative);
StreamResourceInfo sri = Application.GetResourceStream(uri);
bmp.SetSource(sri.Stream);
Image image = new Image();
image.Source = bmp;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM