Pre-Loading Images
I have some animations with PNG images, and they have a slow framerate the first time through. (Especially on large images) I assume this is from loading the image the first time.
Is there a Caching hint or something that will fix this? Or maybe a way to pre-load the images? It isn't a huge problem, I just know it's something someone will complain about on my App.
I've turned the desired framerate down, of course, and it still happens, b/c several of my images are very large. Is this something I'm going to have to live with?
My machine is running Vista, Aero, Tier 2, DWM, all that stuff.
The problem is, these images don't seem to load until they're painted the first time.
For example I have an image like so:
Code Snippet
<Image x:Name="MyImage" Source="\Images\MyPic.png" Stretch="None" />
Say the image is 3000 x 1000 for example, when displayed for the first time in an animation, it is choppy and slow. Each time after the first, it behaves normally.
I want to fix this, and I understand splash screens. How do I get it to pre-load the image during the splash screen?
I understand it would have to be from c#, but would the following work?
Code Snippet
MyImage.Source = new BitmapImage(new Uri("\Images\MyPic.png", UriKind.Relative));
Since no one has answered, maybe I should explain better.
I have a Style with a Trigger for IsVisible = True.
In the trigger's EnterActions I begin a storyboard, and on ExitActions I remove the storyboard.
This style is applied to an Image with a very large/partially transparent png as it's Source.
On the first time the Image is set to visible, the animation is choppy and slow. Every time after is normal.
Any ideas?
Hi Jonathan,
Please try using the BitmapCacheOption.OnLoad. This will decode the entire image upon the inital loading of the image. Also, you can pair this with BitmapCreateOptions.DelayCreation for cases where you are loading many images and don't necessarily want to create the images right away. A good reason for using this option would be if you have a listbox of thousands of images where only tens are displayed at a given time. In this case, if you use the DelayCreation the ones that are not displayed on the screen won't be decoded just yet.
Robert.