现在的位置: 首页 > 综合 > 正文

自己写的比例缩放图片方法,show 一下!

2017年03月16日 ⁄ 综合 ⁄ 共 1175字 ⁄ 字号 评论关闭

/// <summary>
    /// 显示图片
    /// </summary>
    /// <param name="image"></param>
    void ShowImage(string image, int max)
    {
            string str = Server.MapPath("~/productimages/" + image);
            System.Drawing.Bitmap bit = new Bitmap(str);
            double bili = Convert.ToDouble(bit.Height) / Convert.ToDouble(bit.Width);
            if (bit.Width > bit.Height)
            {
                if (bit.Width < max)
                {
                    this.Image1.Width = bit.Width;
                    this.Image1.Height = bit.Height;
                }
                else
                {
                    int height = Convert.ToInt32((bili * max));

                    this.Image1.Width = max;
                    this.Image1.Height = height;
                }
            }
            else
            {
                if (bit.Height < max)
                {
                    this.Image1.Width = bit.Width;
                    this.Image1.Height = bit.Height;
                }
                else
                {
                    int width = Convert.ToInt32(((1 / bili) * max));

                    this.Image1.Width = width;
                    this.Image1.Height = max;
                }
            }

            Image1.ImageUrl = "~/productimages/" + image;

       
    }

抱歉!评论已关闭.