zoukankan      html  css  js  c++  java
  • 创建高质量缩略图

    Thumbnail images are already supplied in certain image formats such as JPEG and TIFF. These are often provided by the camera used to take the picture and can be of very low resolution and sample quality. Unfortunately, if such an image exists you will be handed that one if you use the GetThumbnail method and such low quality images are of little use on screen because the thumbnail often needs to be enlarged before it can be used.

    The only solution is to generate your own thumbnail image of the desired size from the full-sized original. This is accomplished by loading the original, creating an image of the desired size and drawing the original onto the thumbnail. The important thing is quality so in this example the interpolation mode quality is set to HighQualityBilinear which seems to give a slightly nicer effect than HighQualityBicubic. This setting is of course a matter of taste so perhaps you'd like to experiment to see which one you like the best.

        public Image GenerateThumbnail(Image original, int percentage)

        {

          
    if(percentage<1)

            
    throw new Exception("Thumbnail size must be aat least 1% of the original size");

          Bitmap tn
    =new Bitmap((int)(original.Width*0.01f*percentage),(int)(original.Height*0.01f*percentage));

          Graphics g
    =Graphics.FromImage(tn);

          g.InterpolationMode
    =InterpolationMode.HighQualityBilinear; //experiment with this

          g.DrawImage(original, 
    new Rectangle(0,0,tn.Width,tn.Height),0,0,original.Width,original.Height,GraphicsUnit.Pixel);

          g.Dispose();

          
    return (Image)tn;

        }

    申明

    非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

    博文欢迎转载,但请给出原文连接。

  • 相关阅读:
    BZOJ 2064: 分裂( 状压dp )
    BZOJ 2096: [Poi2010]Pilots( set )
    BZOJ 3444: 最后的晚餐( )
    BZOJ 3156: 防御准备( dp + 斜率优化 )
    BZOJ 1770: [Usaco2009 Nov]lights 燈( 高斯消元 )
    BZOJ 2466: [中山市选2009]树( 高斯消元 )
    BZOJ 1316: 树上的询问( 点分治 + 平衡树 )
    codevs 1074
    bzoj 1015
    bzoj 1798
  • 原文地址:https://www.cnblogs.com/Athrun/p/824487.html
Copyright © 2011-2022 走看看