Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the most efficient way to generate thumbnails?

I am developing a graphical application, and I need to keep a thumbnail for each page. The challenge is how to generate a thumbnail file without loosing performance ??

Currently here is my code to do it:

VisualBrush VisualBrush = new VisualBrush(pageToGenerateThumbnailFor);
UIVisual.Background = VisualBrush;

RenderTargetBitmap = new RenderTargetBitmap((int)UIVisual.ActualWidth, (int)UIVisual.ActualHeight, 96, 96, PixelFormats.Pbgra32);

rtb.Render(UIVisual);

using (FileStream outStream = new FileStream(ThumbFileFullPath, FileMode.OpenOrCreate, 
System.IO.FileAccess.ReadWrite))
{
   PngBitmapEncoder pngEncoder = new PngBitmapEncoder();
   pngEncoder.Frames.Add(BitmapFrame.Create(rtb));
   pngEncoder.Save(outStream);
}

So, Is there a faster way to generate a thumbnail for a given Visual ?

Thanks

like image 777
simo Avatar asked Sep 18 '25 20:09

simo


1 Answers

I did a bit of research recently for generating Image Thumbnails on the fly for an eCommerce site. I started off doing this myself generating a bitmap and then resizing etc. similar to the answer above. After problems with image size on disc and quality I looked in to http://imageresizing.net/ and I haven't looked back since. It can generate images from byte(), streams and physicals files all very quickly with one line of code:

ImageBuilder.Current.Build(New MemoryStream(bImage), sImageLocation + sFullFileName, New      ResizeSettings("maxwidth=214&maxheight=238"))

I would definitely recommend this component rather than trying to reinvent the wheel...

like image 50
James Avatar answered Sep 21 '25 10:09

James