• 生成高质量缩略图


    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Imaging;

        private void CreateThumbnail(string sFileSrcPath, string sFileDstPath, int iSizeLimit)
        {
            
    if (File.Exists(sFileSrcPath))
            {
                System.Drawing.Image image 
    = System.Drawing.Image.FromFile(sFileSrcPath) as System.Drawing.Bitmap;

                System.Drawing.SizeF size 
    = new System.Drawing.SizeF(image.Width, image.Height);

                
    while (size.Width > iSizeLimit || size.Height > iSizeLimit)
                {
                    size.Height 
    /= 1.1F;

                    size.Width 
    /= 1.1F;
                }

                System.Drawing.Image bitmap 
    = new System.Drawing.Bitmap(Convert.ToInt16(size.Width), Convert.ToInt16(size.Height));

                System.Drawing.Graphics g 
    = System.Drawing.Graphics.FromImage(bitmap);

                g.SmoothingMode 
    = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                g.Clear(Color.Transparent);

                Rectangle rect 
    = new Rectangle(00, bitmap.Width, bitmap.Height);

                g.DrawImage(image, rect, 
    new System.Drawing.Rectangle(00, image.Width, image.Height), System.Drawing.GraphicsUnit.Pixel);

                ImageCodecInfo myImageCodecInfo;

                Encoder myEncoder;

                EncoderParameter myEncoderParameter;

                EncoderParameters myEncoderParameters;

                myImageCodecInfo 
    = ImageCodecInfo.GetImageEncoders()[0];

                myEncoder 
    = Encoder.Quality;

                myEncoderParameters 
    = new EncoderParameters(1);

                myEncoderParameter 
    = new EncoderParameter(myEncoder, 100L); // 0-100

                myEncoderParameters.Param[
    0= myEncoderParameter;

                bitmap.Save(sFileDstPath, myImageCodecInfo, myEncoderParameters);

                myEncoderParameter.Dispose();

                myEncoderParameters.Dispose();

                image.Dispose();

                bitmap.Dispose();

                g.Dispose();
            }
        }
  • 相关阅读:
    AtCoder Grand Contest 030题解
    Codeforces Round #542 (Div. 1) 题解
    ZJOI2019赛季回顾
    UOJ #450「集训队作业2018」复读机
    「IOI2018」狼人
    APIO2019游记
    BZOJ4314 倍数?倍数!
    伯努利数学习笔记&&Luogu P3711 仓鼠的数学题
    Codeforces Round #541 (Div. 2)题解
    UOJ #460 新年的拯救计划
  • 原文地址:https://www.cnblogs.com/lovecherry/p/433629.html
Copyright © 2020-2023  润新知