ASP.NET Image uploading with Resizing

前端 未结 14 1842
广开言路
广开言路 2020-11-30 01:27

I have an aspx page which will upload images to server harddisk from client pc

But now i need to change my program in such a way that it would allow me to resize the

14条回答
  •  时光取名叫无心
    2020-11-30 01:55

    public string ResizeImageAndSave(int Width, int Height, string imageUrl, string destPath)
        {
            System.Drawing.Image fullSizeImg = System.Drawing.Image.FromFile(imageUrl);
     double widthRatio = (double)fullSizeImg.Width / (double)Width;
      double heightRatio = (double)fullSizeImg.Height / (double)Height;
      double ratio = Math.Max(widthRatio, heightRatio);
     int newWidth = (int)(fullSizeImg.Width / ratio);
     int newHeight = (int)(fullSizeImg.Height / ratio);
            //System.Drawing.Image.GetThumbnailImageAbort dummyCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
            System.Drawing.Image thumbNailImg = fullSizeImg.GetThumbnailImage(newWidth, newHeight, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
     //DateTime MyDate = DateTime.Now;
     //String MyString = MyDate.ToString("ddMMyyhhmmss") + imageUrl.Substring(imageUrl.LastIndexOf("."));
     thumbNailImg.Save(destPath, ImageFormat.Jpeg);
     thumbNailImg.Dispose();
            return "";
        }
        public bool ThumbnailCallback() { return false; }
    

提交回复
热议问题