Jump to content

Imagesize Function


soona

Recommended Posts

hi,Subject: ImageResize in else statement.i am using asp.net with c#.when i upload a image it will check the valid image width and height size.if it is valid saved. if it is invalid got to resize.for example:This is my code to check the valid image width and height size.=======protected void cmdUpdate_Click(System.Object sender, System.EventArgs e) {using (System.Drawing.Bitmap objmap = new System.Drawing.Bitmap(FileUpload1.PostedFile.InputStream, false)) { int one, two; string path2 = ""; one = Convert.ToInt32(fixedWide); two = Convert.ToInt32(fixedHgt); if (objmap.Width == one && objmap.Height == two) { path1 = FileUpload1.PostedFile.FileName.ToString(); path2 = path1.Substring(path1.LastIndexOf("\\") + 1); string getimagepath = Server.MapPath(@"~\ImageFolders\"); getimagepath = getimagepath + Convert.ToString(ModuleId) + "_img_" + path2; FileUpload1.SaveAs(getimagepath); lblMsg.Text = "filesaved"; } else { lblMsg.Text = "Please give valid image size..."; } }}=====This code is run good.my question is: how to call the resize function in else statement.i don't know how to do image resize function. so, please give some idea and related reference source.andi just cut and paste this code in my else part statement: but i don't know this is correct or not?Please verify where can i made mistake?This is my full code for imageupload:================================================protected void cmdUpdate_Click(System.Object sender, System.EventArgs e) { using (System.Drawing.Bitmap objmap = new System.Drawing.Bitmap(FileUpload1.PostedFile.InputStream, false)) { int one, two; string path2 = ""; one = Convert.ToInt32(fixedWide); two = Convert.ToInt32(fixedHgt); if (objmap.Width == one && objmap.Height == two) { path1 = FileUpload1.PostedFile.FileName.ToString(); path2 = path1.Substring(path1.LastIndexOf("\\") + 1); string getimagepath = Server.MapPath(@"~\ImageFolders\"); getimagepath = getimagepath + Convert.ToString(ModuleId) + "_img_" + path2; FileUpload1.SaveAs(getimagepath); lblMsg.Text = "filesaved"; } else { path1 = FileUpload1.PostedFile.FileName.ToString(); path2 = path1.Substring(path1.LastIndexOf("\\") + 1); string getimgfolpath = Server.MapPath(@"~\DesktopModules\Demo\ImageFolders\"); getimgfolpath = getimgfolpath + Convert.ToString(ModuleId) + "_img_" + path2; FileUpload1.SaveAs(getimgfolpath); ImageResizeoption(getimgfolpath,path2); } }} public void ImageResizeoption(string parmFileIn, string Userid) { string filePathSourceFile = HttpContext.Current.Server.MapPath(@"~\ImageFolders\" + ModuleId.ToString() + "/"); string fullSourceFile = parmFileIn; int thumbnailHeight,thumbnailWidth; System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(parmFileIn); thumbnailHeight = 181; thumbnailWidth = 358; System.Drawing.Image thumbnailImage = sourceImage.GetThumbnailImage(thumbnailWidth, thumbnailHeight, null, IntPtr.Zero); MemoryStream imageStream = new MemoryStream(); thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); string outfile = filePathSourceFile + "s" + ModuleId + "_" + Userid; try { thumbnailImage.Save(outfile); } catch (Exception e) { string dummy = e.ToString(); return; } }==========================================In the complete code doesnot shown any error message.Please see where i made mistake in my code(else part statement).Many Thanks

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...