Wednesday, June 01, 2011 2:36 AMI am working on a project which will display lots of thumbnails(>=10000), we can't decode all of thumbnails into memory in one go, so the obvious solution is to only cache part of thumbnails, say 500, when cache is miss, loading thumbnails from DB(we store the raw data in the db, so needn't decode) and create new BitmapSource, when cache is full, we will choose one as victim.The memory consumption of this solution is the still high, since .net will recycle memory in its own rule, and hence browsing performance is bad when gc starts.Our goal is keeping memory in constant size(e.g. <=15M).I tried to re-use BitmapSource, but it looks impossible in the current architecture. this way is good, but our thumbnail will change the width and height.any ideas?
Friday, June 03, 2011 7:08 AMModerator
Hi Chang Chen,
If you have lots of thumbnails to load, I think BitmapSource will not a good way, because if you use bitmapsource to display the image in UI, it will not be disposed as you said, because of reference.
I think you could use Drawing Visual, after you get the image from your DB, you could Draw then on your UI, I think this way could decrease memory consumption, there is a relative thread you could refer to:
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Thursday, June 09, 2011 6:38 AM
Thanks for your reply.
I don't understand what you mean, do you mean using DrawingContext.DrawImage? but it looks
- you still need a BitmapSource derivation
- How do you render this DrawingContext to screen?
From what I understand, BitmapSource is the abstract presentation of bitmap in WPF, analogous thing of Win32 GDI is HBitmap.
As long as we have to use BitmapSource, it looks like InteropBitmap (see this link for InteropBitmap's issue)is the only one choice, since the other BitmapSource derivation still need copy memory, and the memory is freed only at disposing that BitmapSource.