How to get the generated Thumbnail from WpfThumbnailViewer as BitmapImage

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
sebascomeau
Posts: 16
Joined: Fri Jan 31, 2014 5:31 pm

How to get the generated Thumbnail from WpfThumbnailViewer as BitmapImage

Post by sebascomeau » Wed Sep 16, 2015 5:50 pm

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

sebascomeau
Posts: 16
Joined: Fri Jan 31, 2014 5:31 pm

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

Post by sebascomeau » Wed Sep 16, 2015 6:13 pm

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());

Alex
Site Admin
Posts: 1443
Joined: Thu Jul 10, 2008 2:21 pm

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

Post by Alex » Thu Sep 17, 2015 9:50 am

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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests