开发者

WPF - Is RenderTargetBitmap better than changing an Image Source?

开发者 https://www.devze.com 2022-12-12 16:53 出处:网络
Im trying to create a PNG sequencer class that will allow me to change an ImageBrush\'s ImageSource property via an animation.

Im trying to create a PNG sequencer class that will allow me to change an ImageBrush's ImageSource property via an animation.

The issue is that I have around 150 PNG files to load, and it really really affects performance when I have a few animations on the screen.

I have read a little about RenderTargetBitmap and also WriteableBitmap but Im not sure how to get a big performance boost, because I really do need it.

Im getting down to 6fps in some cases, which is obviously not acceptable.

In my Sequencer class, I just update a CurrentFrame DP that changes the ImageSource property of the ImageBrush.

Any ideas on how to increase the performanc开发者_StackOverflow社区e here?


Step 1 is loading all your images in ahead of time (preferably on a background thread). You should have your BitmapImage objects initialized with the CacheOption = BitmapCacheOption.OnLoad. You may already be doing this or it might not be the problem (the images cache by default).

However the rendering thread also needs to do some work when you change the image source. If you're not displaying at the source image size, that might be a problem, as by default the Image control uses the high quality Fant scaling algorithm. In that case you could get a performance increase by calling RenderOptions.SetBitmapScalingMode(uiImage, BitmapScalingMode.LowQuality); on your Image. Low quality scaling is orders of magnitude faster. However even after that there's still a bit of work involved. If you want to get the fastest animation possible, you can create an Image control for every frame, then overlap them all on the same place and change which one appears on top. You'll still take the hit on the render thread loading all the images in, but the actual animation should be quite snappy.

0

精彩评论

暂无评论...
验证码 换一张
取 消