Hi,
I want to compress my image while I'm Uploading. With the help of the C#Corner Website I got that code. But, I facing the Issue in
- Stream strm = ImageFile.PostedFile.InputStream; // Here It shows error in Input stream
- using (var image = System.Drawing.Image.FromStream(strm))
- {
My Full code is here :
- public ActionResult DetailsEdit(EmployeeData___TBL e, string id, HttpPostedFileBase ImageFile)
- {
- var data = Session["userid"].ToString();
- if (e.ImageFile != null)
- {
- string filename = Path.GetFileNameWithoutExtension(e.ImageFile.FileName);
- string extension = Path.GetExtension(e.ImageFile.FileName);
- HttpPostedFileBase postedfile = e.ImageFile;
- int length = postedfile.ContentLength;
- if (extension.ToLower() == ".jpg" || extension.ToLower() == ".jpeg" || extension.ToLower() == ".png")
- {
- if (length <= 1000000)
- {
- filename = filename + extension;
- Stream strm = ImageFile.PostedFile.InputStream;
- using (var image = System.Drawing.Image.FromStream(strm))
- {
- int newWidth = 240; // New Width of Image in Pixel
- int newHeight = 240; // New Height of Image in Pixel
- var thumbImg = new Bitmap(newWidth, newHeight);
- var thumbGraph = Graphics.FromImage(thumbImg);
- thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
- thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
- thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
- var imgRectangle = new Rectangle(0, 0, newWidth, newHeight);
- thumbGraph.DrawImage(image, imgRectangle);
- e.ProfileImage = "~/AppFiles/" + filename;
- filename = Path.Combine(Server.MapPath("~/AppFiles/"), filename);
- e.ImageFile.SaveAs(filename);
- // db.Entry(e).State = EntityState.Modified;
- // int a = db.SaveChanges();
- db.SP_EditUserInfo(data, e.Name, e.EmailID, e.PhoneNo, e.Address, e.ProfileImage);
- //TempData["UpdateMessage"] = "";
- ModelState.Clear();
- return RedirectToAction("Details", "Home");
- }
- }
- }
- else
- {
- e.ProfileImage = Session["Image"].ToString();
- //db.SP_UpdateUserInfo(e.UserId, e.Name, e.EmailID, e.PhoneNo, e.Address, e.ProfileImage);
- //db.Entry(e).State = EntityState.Modified;
- ModelState.Clear();
- return RedirectToAction("List", "Home");
- }
- return View();
- }
- }
Sachin SinghPosted May 12, 2021, 10:02 AM
Kip HackmanPosted Nov 2, 2022, 8:50 PM
You can use LEADTOOLS Imaging Pro SDK technology in your application.
https://www.leadtools.com/sdk/products/imaging-pro
You can leverage the RasterCodecs class, which allows you to load any LEADTOOLS supported raster image format and export to any LEADTOOLS supported raster image format. You can utilize the RasterImageFormat enumeration and QualityFactor property, to indicate the image compression type and to specify the tradeoff between quality and compression.
https://www.leadtools.com/help/sdk/v21/dh/to/compression-quality-factors.html
I am unaware of the file format you are using, so the code below uses JPEG:
Sachin SinghPosted May 12, 2021, 9:53 AM
vijayaasri palaniappanPosted May 12, 2021, 8:27 AM
Sachin SinghPosted May 12, 2021, 8:18 AM
vijayaasri palaniappanPosted May 12, 2021, 7:20 AM
Salman BegPosted May 12, 2021, 6:57 AM