Image Resize and stored in server folder


           
           



           
            if (fileupload.HasFile)
       {
           imagename = txtimgtitle.Text;
           string fileName = Path.GetFileName(fileupload.PostedFile.FileName);
           string strpath = System.IO.Path.GetExtension(fileupload.PostedFile.FileName);
           string dt = DateTime.Now.ToString("MM_dd_yyyy_hh_mm_ss") + "_";


           Stream stream = fileupload.PostedFile.InputStream;
           var image = System.Drawing.Image.FromStream(stream);
           //extra large
           //Stream exlargestrm = fileupload.PostedFile.InputStream;
           //var extrallargeimage = System.Drawing.Image.FromStream(exlargestrm);
           int ExtralargeWidth = 5616; // New Width of Image in Pixel 
           int ExtralargeHeight = 3744; // New Height of Image in Pixel
           var thumbImg = new Bitmap(ExtralargeWidth, ExtralargeHeight);
           var thumbGraph = Graphics.FromImage(thumbImg);
           thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
           thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
           thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
           var imgRectangle = new Rectangle(0, 0, ExtralargeWidth, ExtralargeHeight);
           thumbGraph.DrawImage(image, imgRectangle);
           string targetPath = Server.MapPath("~/admin/images/extralarge/") + dt + imagename + strpath;
           thumbImg.Save(targetPath, image.RawFormat);
           //large
           //Stream largestrm = fileupload.PostedFile.InputStream;
           //var largeimage = System.Drawing.Image.FromStream(exlargestrm);
           int largeWidth = 2125; // New Width of Image in Pixel 
           int largeHeight = 1416; // New Height of Image in Pixel
           var largethumbImg = new Bitmap(largeWidth, largeHeight);
           var largethumbGraph = Graphics.FromImage(largethumbImg);
           largethumbGraph.CompositingQuality = CompositingQuality.HighQuality;
           largethumbGraph.SmoothingMode = SmoothingMode.HighQuality;
           largethumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
           var largeimgRectangle = new Rectangle(0, 0, largeWidth, largeHeight);
           largethumbGraph.DrawImage(image, largeimgRectangle);
           string largetargetPath = Server.MapPath("~/admin/images/large/") + dt + imagename + strpath;
           largethumbImg.Save(largetargetPath, image.RawFormat);
           // small
          // Stream smallstrm = fileupload.PostedFile.InputStream;
           //var smallimage = System.Drawing.Image.FromStream(exlargestrm);
           int smallWidth = 727; // New Width of Image in Pixel 
           int smallHeight = 484; // New Height of Image in Pixel
           var smallthumbImg = new Bitmap(smallWidth, smallHeight);
           var smallthumbGraph = Graphics.FromImage(smallthumbImg);
           smallthumbGraph.CompositingQuality = CompositingQuality.HighQuality;
           smallthumbGraph.SmoothingMode = SmoothingMode.HighQuality;
           smallthumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
           var smallimgRectangle = new Rectangle(0, 0, smallWidth, smallHeight);
           smallthumbGraph.DrawImage(image, smallimgRectangle);
           string smalltargetPath = Server.MapPath("~/admin/images/small/") + dt + imagename + strpath;
           smallthumbImg.Save(smalltargetPath, image.RawFormat);
           //extra small
           //Stream extrasmallstrm = fileupload.PostedFile.InputStream;
           //var extralsmallimage = System.Drawing.Image.FromStream(exlargestrm);
           int ExtrasmallWidth = 509; // New Width of Image in Pixel 
           int ExtrasmallHeight = 339; // New Height of Image in Pixel
           var ExsmallthumbImg = new Bitmap(ExtrasmallWidth, ExtrasmallHeight);
           var ExsmallthumbGraph = Graphics.FromImage(ExsmallthumbImg);
           ExsmallthumbGraph.CompositingQuality = CompositingQuality.HighQuality;
           ExsmallthumbGraph.SmoothingMode = SmoothingMode.HighQuality;
           ExsmallthumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
           var ExsmallimgRectangle = new Rectangle(0, 0, ExtrasmallWidth, ExtrasmallHeight);
           ExsmallthumbGraph.DrawImage(image, ExsmallimgRectangle);
           string ExsmalltargetPath = Server.MapPath("~/admin/images/extrasmall/") + dt + imagename + strpath;
           ExsmallthumbImg.Save(ExsmalltargetPath, image.RawFormat);

           //fileupload.PostedFile.SaveAs(Server.MapPath("~/admin/images/") + dt + imagename + strpath);
           entities.IMAGE_TITLE = txtimgtitle.Text;
           entities.IMAGE_TYPE = ddlimgtype.Value.ToLower();
           entities.IMAGE_COST = Convert.ToInt32(txtimgcost.Text);
           entities.IMAGE_PRIORITY = Convert.ToInt32(txtimgpriority.Text);
           entities.IMAGE_DESCRIPTION = txtdescription.Text;
           entities.IMAGE_PATH = "../admin/images/extralarge/" + dt + imagename + strpath;
           entities.IMAGE_CREATED_DATE = DateTime.Now;
           entities.IMAGE_CREATED_BY = "Eswar datta";
           entities.IMAGE_PATH_LARGE = "../admin/images/large/" + dt + imagename + strpath;
           entities.IMAGE_PATH_MEDIUM = "../admin/images/extrasmall/" + dt + imagename + strpath;
           entities.IMAGE_PATH_SMALL = "../admin/images/small/" + dt + imagename + strpath;
           BAL.Insertimage(entities);
           ClearInputs(Page.Controls);
           Gridbind();
           alert.Visible = true;
           alertlabel.InnerText = "Added Successfully";
       }


Comments

  1. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. Click here to visit Best Online education in India

    ReplyDelete

Post a Comment

Popular posts from this blog

Automatically send Birthday email using C#.Net

Drag and Drop multiple File upload using jQuery AJAX in ASP.Net using C# and VB.Net

Difference between each and map in jquery