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
            {
            }
        }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-05-25
  • 2021-09-15
  • 2021-06-23
  • 2021-11-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
  • 2022-01-22
  • 2021-11-09
相关资源
相似解决方案