zoukankan      html  css  js  c++  java
  • 缩略图(转载)

    public void GreateMiniImage(string oldpath, string newpath, int tWidth, int tHeight)
            {
                try
                {
                    System.Drawing.Image image = System.Drawing.Image.FromFile(oldpath);
                    double bl = 1d;
                    if ((image.Width <= image.Height) && (tWidth >= tHeight))
                    {
                        bl = Convert.ToDouble(image.Height) / Convert.ToDouble(tHeight);
                    }
                    else if ((image.Width > image.Height) && (tWidth < tHeight))
                    {
                        bl = Convert.ToDouble(image.Width) / Convert.ToDouble(tWidth);
                    }
                    else if ((image.Width <= image.Height) && (tWidth <= tHeight))
                    {
                        if (image.Height / tHeight >= image.Width / tWidth)
                        {
                            bl = Convert.ToDouble(image.Width) / Convert.ToDouble(tWidth);
                        }
                        else
                        {
                            bl = Convert.ToDouble(image.Height) / Convert.ToDouble(tHeight);
                        }
                    }
                    else
                    {
                        if (image.Height / tHeight >= image.Width / tWidth)
                        {
                            bl = Convert.ToDouble(image.Height) / Convert.ToDouble(tHeight);
                        }
                        else
                        {
                            bl = Convert.ToDouble(image.Width) / Convert.ToDouble(tWidth);
                        }
                    }
                    Bitmap b = new Bitmap(image, Convert.ToInt32(image.Width / bl), Convert.ToInt32(image.Height / bl));
                    //保存本地
                    b.Save(newpath);
                    //输出客户端
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    b.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                    Response.ClearContent();
                    Response.ContentType = "image/Gif";
                    Response.BinaryWrite(ms.ToArray());

                    b.Dispose();
                    image.Dispose();
                }
                catch
                {
                }
            }

    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    【Thymeleaf/SpringBoot/MyBatis】如何将themeleaf页面的表单数据提交到后台处理
    【Oracle】生成连续序列的两种方法
    【oracle】统计字段里逗号的数量,采用函数regexp(field,',')
    人的成长与发展不会一帆风顺,坚守理想和信念,不以一时颠簸为意,才能更好地走向未来。
    【SpringBoot/Thymeleaf】如何使SpringBoot程序显示网页
    【jQuery/Thymeleaf】在Thymeleaf页面用jQuery的Ajax方法取得后台数据显示在页面上
    JavaScript常用正則表達式
    CSS的入門
    ASP操作xml之如何生成XML数据
    ISAPI筛选器及对ASP源文件的保护
  • 原文地址:https://www.cnblogs.com/starcrm/p/1316603.html
Copyright © 2011-2022 走看看