private void SetImage(Westgate.Data.Image image) { string beforeImagePath = image.BeforeImagePath; if (beforeImagePath != null) { beforeImage = System.Drawing.Image.FromFile(Server.MapPath(image.BeforeImagePath)); beforeImagePath=viewImage(beforeImage, "Before"); } string afterImagePath = image.AfterImagePath; if (afterImagePath != null) { afterImage = System.Drawing.Image.FromFile(Server.MapPath(image.AfterImagePath)); afterImagePath=viewImage(afterImage, "After"); } if (beforeImagePath != null && afterImagePath != "") { String path = CreateCombinedImage(beforeImagePath, afterImagePath); if (path != null) { image.CombinedImagePath = path; } } }
private bool SetImage(Westgate.Data.Image image) { if (Request["tagId"] != null) { int tagId = int.Parse(Request["tagId"] ); Tag tag = (from t in DatabaseContext.Tags where t.TagId == tagId select t).FirstOrDefault(); ImageTag imgTag = new ImageTag { Image = image, Tag = tag }; DatabaseContext.ImageTags.AddObject(imgTag); DatabaseContext.SaveChanges(); // image.StoryId = int.Parse(Request["StoryId"]); }else{ } image.Name = tbName.Text; image.Description = tbDescription.Text; string beforeImagePath = SaveFile(fileBeforeImage); if (beforeImagePath != null) { BeforeAcutalImage.Value = beforeImagePath; image.BeforeImagePath = beforeImagePath; beforeImage = System.Drawing.Image.FromFile(Server.MapPath(beforeImagePath)); imgBefore.ImageUrl = viewImage(beforeImage, "Before"); int quarterWidth = Convert.ToInt32(BeforeImageWidth.Value) / 4; int quarterHeight = Convert.ToInt32(BeforeImageHeight.Value) / 4; BeforeX1 = Convert.ToString(quarterWidth); BeforeX2 = Convert.ToString(quarterWidth * 3); BeforeY1 = Convert.ToString(quarterHeight); BeforeY2 = Convert.ToString(quarterHeight * 3); BeforeImageX1.Value = BeforeX1; BeforeImageX2.Value = BeforeX2; BeforeImageY1.Value = BeforeY1; BeforeImageY2.Value = BeforeY2; } else { if (imgBefore.ImageUrl == null || imgBefore.ImageUrl =="") { imgBefore.ImageUrl = ""; imgAfter.ImageUrl = ""; ErrorMsg.Visible = true; return false; } } string afterImagePath = SaveFile(fileAfterImage); if (afterImagePath != null) { AfterActualImage.Value = afterImagePath; image.AfterImagePath = afterImagePath; afterImage = System.Drawing.Image.FromFile(Server.MapPath(afterImagePath)); imgAfter.ImageUrl = viewImage(afterImage, "After"); int quarterWidth = Convert.ToInt32(AfterImageWidth.Value) / 4; int quarterHeight = Convert.ToInt32(AfterImageHeight.Value) / 4; AfterX1 = Convert.ToString(quarterWidth); AfterX2 = Convert.ToString(quarterWidth * 3); AfterY1 = Convert.ToString(quarterHeight); AfterY2 = Convert.ToString(quarterHeight * 3); AfterImageX1.Value = AfterX1; AfterImageX2.Value = AfterX2; AfterImageY1.Value = AfterY1; AfterImageY2.Value = AfterY2; } else { if (imgAfter.ImageUrl == null || imgAfter.ImageUrl == "") { imgBefore.ImageUrl = ""; imgAfter.ImageUrl = ""; ErrorMsg.Visible = true; return false; } } if (imgBefore.ImageUrl != null && imgBefore.ImageUrl != "" && imgAfter.ImageUrl != null && imgAfter.ImageUrl != "") { String path = CreateCombinedImage(imgBefore.ImageUrl, imgAfter.ImageUrl); if (path != null) { image.CombinedImagePath = path; imgCombined.ImageUrl = path; return true; } else { ErrorMsg.Visible = true; return false; } } return true; }
private void SetImage(Westgate.Data.Image image) { if (Request["tagId"] != null) { int tagId = int.Parse(Request["tagId"]); Tag tag = (from t in DatabaseContext.Tags where t.TagId == tagId select t).FirstOrDefault(); ImageTag imgTag = new ImageTag { Image = image, Tag = tag }; DatabaseContext.ImageTags.AddObject(imgTag); DatabaseContext.SaveChanges(); } // image.StoryId = int.Parse(ddlStories.SelectedValue); image.Name = tbName.Text; image.Description = tbDescription.Text; string beforeImagePath = SaveFile(fileBeforeImage); if (beforeImagePath != null) { BeforeAcutalImage.Value = beforeImagePath; image.BeforeImagePath = beforeImagePath; beforeImage = System.Drawing.Image.FromFile(Server.MapPath(beforeImagePath)); imgBefore.ImageUrl = viewImage(beforeImage, "Before"); int quarterWidth = Convert.ToInt32(BeforeImageWidth.Value) / 4; int quarterHeight = Convert.ToInt32(BeforeImageHeight.Value) / 4; BeforeX1 = Convert.ToString(quarterWidth); BeforeX2 = Convert.ToString(quarterWidth * 3); BeforeY1 = Convert.ToString(quarterHeight); BeforeY2 = Convert.ToString(quarterHeight * 3); BeforeImageX1.Value=BeforeX1; BeforeImageX2.Value=BeforeX2; BeforeImageY1.Value=BeforeY1; BeforeImageY2.Value = BeforeY2; } string afterImagePath = SaveFile(fileAfterImage); if (afterImagePath != null) { AfterActualImage.Value = afterImagePath; image.AfterImagePath = afterImagePath; afterImage = System.Drawing.Image.FromFile(Server.MapPath(afterImagePath)); imgAfter.ImageUrl = viewImage(afterImage, "After"); int quarterWidth = Convert.ToInt32(AfterImageWidth.Value) / 4; int quarterHeight = Convert.ToInt32(AfterImageHeight.Value) / 4; AfterX1 = Convert.ToString(quarterWidth); AfterX2 = Convert.ToString(quarterWidth * 3); AfterY1 = Convert.ToString(quarterHeight); AfterY2 = Convert.ToString(quarterHeight * 3); AfterImageX1.Value = AfterX1; AfterImageX2.Value = AfterX2; AfterImageY1.Value = AfterY1; AfterImageY2.Value = AfterY2; } if (imgBefore.ImageUrl != null && imgBefore.ImageUrl != "" && imgAfter.ImageUrl != null && imgAfter.ImageUrl!="") { String path = CreateCombinedImage(imgBefore.ImageUrl, imgAfter.ImageUrl); if (path != null) { image.CombinedImagePath = path; imgCombined.ImageUrl = path; } } /* if (BeforeX1 != null && BeforeX1 != "" && AfterX1!=null && AfterX1!="") { //beforeImage = System.Drawing.Image.FromFile(Server.MapPath(image.BeforeImagePath)); //afterImage = System.Drawing.Image.FromFile(Server.MapPath(image.AfterImagePath)); //double beforeActualHeight = (double)beforeImage.PhysicalDimension.Height / (double)Convert.ToInt32(BeforeImageHeight.Value); //double beforeActualWidth = (double)beforeImage.PhysicalDimension.Width / (double)Convert.ToInt32(BeforeImageWidth.Value); //double afterActualHeight = (double)afterImage.PhysicalDimension.Height / (double)Convert.ToInt32(AfterImageHeight.Value); //double afterActualWidth = (double)afterImage.PhysicalDimension.Width / (double)Convert.ToInt32(AfterImageWidth.Value); //int beforeX = (int)((double)Convert.ToDouble(BeforeX1) * beforeActualWidth); //int beforeY = (int)((double)Convert.ToDouble(BeforeY1) * beforeActualHeight); //int beforeWidth = (int)((double)(Convert.ToDouble(BeforeX2) - Convert.ToDouble(BeforeX1)) * beforeActualWidth); //int beforeHeight = (int)((double)(Convert.ToDouble(BeforeY2) - Convert.ToDouble(BeforeY1)) * beforeActualHeight); //int afterX = (int)((double)Convert.ToDouble(AfterX1) * afterActualWidth); //int afterY = (int)((double)Convert.ToDouble(AfterY1) * afterActualHeight); //int afterWidth = (int)((double)(Convert.ToDouble(AfterX2) - Convert.ToDouble(AfterX1))*afterActualWidth); //int afterHeight = (int)((double)(Convert.ToDouble(AfterY2) - Convert.ToDouble(AfterY1))*afterActualHeight); Bitmap beforeCropImage = new Bitmap(936, 350); Graphics graphic = Graphics.FromImage(beforeCropImage); graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; //Rectangle beforeCropArea = new Rectangle(beforeX, beforeY, beforeWidth, beforeHeight); //Rectangle afterCropArea = new Rectangle(afterX, afterY, afterWidth, afterHeight); Rectangle cropArea1 = new Rectangle(0, 0, 468, 350); Rectangle cropArea2 = new Rectangle(468, 0, 468, 350); graphic.DrawImage(beforeImage, cropArea1, beforeCropArea, GraphicsUnit.Pixel); graphic.DrawImage(afterImage, cropArea2, afterCropArea, GraphicsUnit.Pixel); graphic.Dispose(); string fileName = System.Guid.NewGuid().ToString() + ".png"; string path = Server.MapPath("~/UserImages") + @"\" + fileName; beforeCropImage.Save(path); image.CombinedImagePath = "~/UserImages/" + fileName; imgCombined.ImageUrl = image.CombinedImagePath; } */ }