How to resize and save an image which uploaded using file upload control in c#

前端 未结 1 572
青春惊慌失措
青春惊慌失措 2020-12-24 03:45

i have developed a web application using asp.net mvc4 and razor. in my application there\'s a file upload control to upload an image and save in a temporary location.

<
相关标签:
1条回答
  • 2020-12-24 04:27

    Its very difficult to understand what is the problem with your code. But may be you want to use alternative way. You need to add the reference to System.Web.Helpers namespace and try the following code.

    [HttpPost]
        public ActionResult Index(HttpPostedFileBase file)
        {
            WebImage img = new WebImage(file.InputStream);
            if (img.Width > 1000)
                img.Resize(1000, 1000);
            img.Save("path");
            return View();
        }
    

    Also this class supports the crop, flip, watermark operation etc.

    0 讨论(0)
提交回复
热议问题