Page 1 of 1

How to get the generated Thumbnail from WpfThumbnailViewer as BitmapImage

Posted: Wed Sep 16, 2015 5:50 pm
by sebascomeau
How to get the generated Thumbnail from WpfThumbnailViewer as BitmapImage. My code always return the full size of the original image. Something`s wrong with my code or yours.

Here`s my code

Code: Select all

// generate thumbnail image source
BitmapImage imageSource = new BitmapImage();

using(MemoryStream ms = new MemoryStream())
{
    thumbnailImageItem.Source.Thumbnail.GetThumbnailImage(64, 64).Save(ms, new Vintasoft.Imaging.Codecs.Encoders.JpegEncoder());
                        
    ms.Seek(0, SeekOrigin.Begin);
    imageSource.BeginInit();
    imageSource.StreamSource = ms;
    imageSource.EndInit();
}
Sébastien Comeau

Re: How to get the generated Thumbnail from WpfThumbnailViewer as BitmapImage

Posted: Wed Sep 16, 2015 6:13 pm
by sebascomeau
I change my code and the with and height of my bitmap is now good.

Code: Select all

BitmapSource imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(thumbnailImageItem.Source.Thumbnail.GetThumbnailImage(64, 64).GetAsBitmap().GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

Re: How to get the generated Thumbnail from WpfThumbnailViewer as BitmapImage

Posted: Thu Sep 17, 2015 9:50 am
by Alex
Hello Sebastien,

Your code is very complex.

You can get generated thumbnail from WpfThumbnailViewer as BitmapImage using the following code:

Code: Select all

BitmapSource thumbnailBitmap = ThumbnailImageItem.ThumbnailSource;
Also at any time you can render thumbnail of any size using the following code:

Code: Select all

BitmapSource thumbnailBitmap;
VintasoftImage image = thumbnailImageItem.Source;
using (VintasoftImage thumbnailImage = image.Thumbnail.GetThumbnailImage(128,128))
  thumbnailBitmap = VintasoftImageConverter.ToBitmapSource(thumbnailImage);
Best regards, Alexander