// Generate thumbs and midthumbs from photos public static string Generate_Thumbs(string path, string thumbpath, string midthumbpath, int thumbwidth, int midthumbwidth) { Bitmap mp = null; Bitmap midmp = null; Copy_Photo(path, thumbpath); Copy_Photo(path, midthumbpath); // Generate Normal Thumb mp = Image_Process.CreateThumbnail(path, thumbwidth); midmp = Image_Process.CreateThumbnail(path, midthumbwidth); if (mp == null) { return(""); } mp.Save(thumbpath); midmp.Save(midthumbpath); //*********************** // Compress Thumb Photo //*********************** // Mid thumbs Image_Process.SaveJpeg(midthumbpath, midmp, 60); // Thumbs Image_Process.SaveJpeg(thumbpath, mp, 90); mp.Dispose(); midmp.Dispose(); return("1"); }
protected void btn_save_Click(object sender, EventArgs e) { string strPath = Server.MapPath(Request.ApplicationPath) + "//contents//member//" + this.UserName + "//photos//"; // delete old user profile photo if exist if (this.PhotoName != "none" || !this.PhotoName.Contains("http")) { try { if (File.Exists(strPath + "" + this.PhotoName)) { File.Delete(strPath + "" + this.PhotoName); } if (File.Exists(strPath + "thumbs/" + this.PhotoName)) { File.Delete(strPath + "thumbs/" + this.PhotoName); } } catch (Exception ex) { //Response.Redirect( Config.GetUrl("user/Profile.aspx?status=derror")); } } // update new photo string filename = Guid.NewGuid().ToString().Substring(0, 10) + "" + ph1.PostedFile.FileName.Remove(0, ph1.PostedFile.FileName.LastIndexOf(".")); if (!UtilityBLL.isImage(ph1.PostedFile.ContentType)) { Response.Redirect(Config.GetUrl("myaccount/Profile.aspx?status=invalidformat")); return; } ph1.PostedFile.SaveAs(strPath + "" + filename); ph1.PostedFile.SaveAs(strPath + "thumbs/" + filename); string orignalfilename = strPath + "" + filename; string thumbfilename = strPath + "thumbs/" + filename; Bitmap mp = Image_Process.CreateThumbnail(orignalfilename, 92); if (mp == null) { Response.Redirect(Config.GetUrl("myaccount/Profile.aspx?status=perror")); return; } mp.Save(thumbfilename); Image_Process.SaveJpeg(thumbfilename, mp, 90); mp.Dispose(); members.Update_Value(this.UserName, "PictureName", filename); Response.Redirect(Config.GetUrl("myaccount/Profile.aspx?status=pupdated")); }