How to thumbnail faster in c#

[亡魂溺海] 提交于 2019-12-06 12:06:45

Your calculations happen in fractions of a second. The call to DrawImage is most likely the slowest part of this (as that one is doing the scaling).

If you're needing this thumbnail image exactly once then I don't see much room for improvement here. If you're calling that method on the same image more than once, you should cache the thumbnails.

Out of curiosity, have you tried the GetThumbnailImage method on System.Drawing.Bitmap? It might at least be worth comparing to your current implementation.

I use this mechanism which seems to be very fast.

               BitmapFrame bi = BitmapFrame.Create(new Uri(value.ToString()), BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand);

            // If this is a photo there should be a thumbnail image, this is VERY fast
            if (bi.Thumbnail != null)
            {
                return bi.Thumbnail;
            }
            else
            {
                // No thumbnail so make our own (Not so fast)
                BitmapImage bi2 = new BitmapImage();
                bi2.BeginInit();
                bi2.DecodePixelWidth = 100;
                bi2.CacheOption = BitmapCacheOption.OnLoad;
                bi2.UriSource = new Uri(value.ToString());
                bi2.EndInit();
                return bi2;
            }

Hope this helps.

This may seem like to much of an obvious answer but have you tried just using Image.GetThumbnailImage()?

You don't get as much control over the quality of the result but if speed is your main concern?

Your thumbnail extraction that gets you the big speed up relies on the image having a thumbnail already embedded in it.

To speed up the original you might find that changing:-

graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

to

graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low;

Might help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!