Shihan Khan
Shihan Khan

Reputation: 2188

Image size gets bigger after upload

I'm using asp.net mvc 4 to upload images on my server. I'm using WebImage class to resize my images before uploading.

But I'm now sure why but my image file size is getting bigger after upload which shouldn't be happening because I'm resizing the original image to a smaller size before uploading.

Here is my code for uploading:

    [HttpPost]
    public ActionResult FlatImageOne(HttpPostedFileBase file, int getFlId)
    {
        if (file != null && file.ContentLength > 0)
        {
            string picName = getFlId.ToString() + "-0";
            WebImage img = new WebImage(file.InputStream);
            string picExt = Path.GetExtension(file.FileName);
            if (picExt == ".jpg" || picExt == ".gif" || picExt == ".jpeg" || picExt == ".png")
            {
                picExt = "PNG";
                string path = System.IO.Path.Combine(Server.MapPath("~/Images/Flats/"), picName);
                var img_resized = img.Resize(721, 482, false, false);
                img_resized.Save(path, picExt);
                return RedirectToAction("FlatImageOne", new { FlId = getFlId });
            }
            else
            {
                return RedirectToAction("FlatImageOne", new { FlId = getFlId });
            }
        }
        else
        {
            return RedirectToAction("FlatImageOne", new { FlId = getFlId });
        }
    }

How can I solve this issue?

Upvotes: 2

Views: 703

Answers (0)

Related Questions