MemoryStream and BitmapSource

Posted by Vinjamuri on Stack Overflow See other posts from Stack Overflow or by Vinjamuri
Published on 2010-05-21T02:31:41Z Indexed on 2010/05/21 2:50 UTC
Read the original article Hit count: 1117

Filed under:
|

I have a MemoryStream of 10K which was created from a bitmap of 2MB and compressed using JPEG. Since MemoryStream can’t directly be placed in System.Windows.Controls.Image for the GUI, I am using the following intermediate code to convert this back to BitmapImage and eventually System.Windows.Controls.Image.

            System.Windows.Controls.Image image = new System.Windows.Controls.Image();
            BitmapImage imageSource = new BitmapImage();
            s.SlideInformation.Thumbnail.Seek(0, SeekOrigin.Begin);
            imageSource.BeginInit();
            imageSource.CacheOption = BitmapCacheOption.OnDemand; 
            imageSource.CreateOptions = BitmapCreateOptions.DelayCreation;
            imageSource.StreamSource = s.SlideInformation.Thumbnail;
            imageSource.EndInit();
            imageSource.Freeze();
            image.Source = imageSource;
            ret = image.Source;

My question is, when I store this in BitmapImage, the memory allocation is taking around 2MB. Is this expected? Is there any way to reduce the memory?

I have around 300 thumbnails and this converstion takes around 600MB, which is very high.

Appreciate your help!

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpf-controls