• 生成高清缩略图


      public void CreatePic(int width)
            {
                //本例中假定了两个变量:

                String src = @"C:\Documents and Settings\Administrator\桌面\www\WaterMark\WaterMark\images111\www\1.jpg";   //源图像文件的绝对路径

                String dest = @"C:\Documents and Settings\Administrator\桌面\www\WaterMark\WaterMark\images111\www\373737.jpg";     //生成的缩略图图像文件的绝对路径

                int thumbWidth = width;    //要生成的缩略图的宽度

                System.Drawing.Image image =  System.Drawing.Image.FromFile(src); ; //利用Image对象装载源图像
           

                //接着创建一个System.Drawing.Bitmap对象,并设置你希望的缩略图的宽度和高度。

                int srcWidth = image.Width;
                int srcHeight = image.Height;
                int thumbHeight = Convert.ToInt16((Convert.ToSingle(srcHeight) / Convert.ToSingle(srcWidth)) * Convert.ToSingle(thumbWidth));
                Bitmap bmp = new Bitmap(thumbWidth, thumbHeight);

                //从Bitmap创建一个System.Drawing.Graphics对象,用来绘制高质量的缩小图。

                System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmp);

                //设置 System.Drawing.Graphics对象的SmoothingMode属性为HighQuality

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

                //下面这个也设成高质量

                gr.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;

                //下面这个设成High

                gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

                //把原始图像绘制成上面所设置宽高的缩小图

                System.Drawing.Rectangle rectDestination = new System.Drawing.Rectangle(0, 0, thumbWidth, thumbHeight);
                gr.DrawImage(image, rectDestination, 0, 0, srcWidth, srcHeight, GraphicsUnit.Pixel);

                //保存图像,大功告成!

                bmp.Save(dest);

                //最后别忘了释放资源
                bmp.Dispose();
                image.Dispose();
            }

  • 相关阅读:
    Python3之random模块常用方法
    Go语言学习笔记(九)之数组
    Go语言学习笔记之简单的几个排序
    Go语言学习笔记(八)
    Python3之logging模块
    Go语言学习笔记(六)
    123. Best Time to Buy and Sell Stock III(js)
    122. Best Time to Buy and Sell Stock II(js)
    121. Best Time to Buy and Sell Stock(js)
    120. Triangle(js)
  • 原文地址:https://www.cnblogs.com/weichuo/p/1272790.html
Copyright © 2020-2023  润新知