private void SingleBurlyWoodFrame(PhotoGallery.Models.Image img) { //Response.Clear(); Bitmap bmp = new Bitmap(Server.MapPath(img.Path)); int height = bmp.Height; int width = bmp.Width; Bitmap bmp1 = new Bitmap(width, height, PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(bmp); Graphics g1 = Graphics.FromImage(bmp1); g1.DrawImage(bmp, new Rectangle(0, 0, width, height), new Rectangle(0, 0, width, height), GraphicsUnit.Pixel); g1.TextRenderingHint = TextRenderingHint.AntiAlias; Pen burlyWoodPen = new Pen(Brushes.BurlyWood); burlyWoodPen.Width = 24.0F; g1.DrawRectangle(burlyWoodPen, 0, 0, width, height); string _imagepath = Server.MapPath(img.Path); g.Dispose(); bmp.Dispose(); System.IO.File.Delete(_imagepath); bmp1.Save(_imagepath, ImageFormat.Jpeg); g1.Dispose(); bmp1.Dispose(); //Response.End(); }
public ActionResult Update(EventFormViewModel eventModel) { if (UserSession() == 0) { return(RedirectToAction("Index", "Sessions")); } var dbEvent = _context.Event.SingleOrDefault(m => m.Id == eventModel.Event.Id); if (!ModelState.IsValid) { var viewModel = new EventFormViewModel { Event = dbEvent }; return(View("Edit", viewModel)); } dbEvent.Name = eventModel.Event.Name; dbEvent.Description = eventModel.Event.Description; dbEvent.UserId = eventModel.Event.UserId; dbEvent.location = eventModel.Event.location; if (eventModel.UploadedImages[0] != null) { var imgs = _context.Image.Where(m => m.EventId == dbEvent.Id); foreach (var img in imgs) { _context.Image.Remove(img); } foreach (var img in eventModel.UploadedImages) { PhotoGallery.Models.Image imgObj = new PhotoGallery.Models.Image(); string filename = Path.GetFileNameWithoutExtension(img.FileName); string extension = Path.GetExtension(img.FileName); filename = filename + DateTime.Now.ToString("yymm") + extension; imgObj.Name = filename; string relative_path = "/Images/" + filename; imgObj.Path = relative_path; string filepath = Server.MapPath("~" + relative_path); imgObj.EventId = dbEvent.Id; img.SaveAs(filepath); _context.Image.Add(imgObj); _context.SaveChanges(); } } _context.SaveChanges(); return(RedirectToAction("Detail", new { id = eventModel.Event.Id })); }
private void TripleColorsFrame(PhotoGallery.Models.Image img) { //Response.Clear(); Bitmap bmp = new Bitmap(Server.MapPath(img.Path)); int height = bmp.Height; int width = bmp.Width; Bitmap bmp1 = new Bitmap(width, height, PixelFormat.Format24bppRgb); //Graphics g = Graphics.FromImage(bmp); Graphics g1 = Graphics.FromImage(bmp1); g1.DrawImage(bmp, new Rectangle(0, 0, width, height), new Rectangle(0, 0, width, height), GraphicsUnit.Pixel); g1.TextRenderingHint = TextRenderingHint.AntiAlias; Pen whitePen = new Pen(Brushes.White); Pen orangePen = new Pen(Brushes.Orange); Pen redPen = new Pen(Brushes.Red); whitePen.Width = 8.0F; orangePen.Width = 8.0F; redPen.Width = 8.0F; g1.DrawRectangle(whitePen, 10, 10, width - 20, height - 20); g1.DrawRectangle(orangePen, 5, 5, width - 12, height - 12); g1.DrawRectangle(redPen, 0, 0, width, height); string _imagepath = Server.MapPath(img.Path); //g.Dispose(); bmp.Dispose(); System.IO.File.Delete(_imagepath); bmp1.Save(_imagepath, ImageFormat.Jpeg); g1.Dispose(); bmp1.Dispose(); //Response.End(); }
private void AddFrame(Frame frame, PhotoGallery.Models.Image img) { switch (frame.Code) { case 1: SinglePurpleFrame(img); break; case 2: SingleBurlyWoodFrame(img); break; case 3: DoubleColorsFrame(img); break; case 4: TripleColorsFrame(img); break; } }
private void DoubleColorsFrame(PhotoGallery.Models.Image img) { //Response.Clear(); Bitmap bmp = new Bitmap(Server.MapPath(img.Path)); int height = bmp.Height; int width = bmp.Width; Bitmap bmp1 = new Bitmap(width, height, PixelFormat.Format24bppRgb); //Graphics g = Graphics.FromImage(bmp); Graphics g1 = Graphics.FromImage(bmp1); g1.DrawImage(bmp, new Rectangle(0, 0, width, height), new Rectangle(0, 0, width, height), GraphicsUnit.Pixel); g1.TextRenderingHint = TextRenderingHint.AntiAlias; Pen cadetBluePen = new Pen(Brushes.CadetBlue); Pen darkGreenPen = new Pen(Brushes.DarkGreen); cadetBluePen.Width = 12.0F; darkGreenPen.Width = 12.0F; g1.DrawRectangle(cadetBluePen, 5, 5, width - 12, height - 12); g1.DrawRectangle(darkGreenPen, 0, 0, width, height); string _imagepath = Server.MapPath(img.Path); //g.Dispose(); bmp.Dispose(); System.IO.File.Delete(_imagepath); bmp1.Save(_imagepath, ImageFormat.Jpeg); g1.Dispose(); bmp1.Dispose(); //Response.End(); }
public ActionResult Create(EventFormViewModel eventModel) { if (UserSession() == 0) { return(RedirectToAction("Index", "Events")); } if (!ModelState.IsValid) { var dbEvent = new Event(); var viewModel = new EventFormViewModel { Event = dbEvent }; return(View("New", viewModel)); } _context.Event.Add(eventModel.Event); _context.SaveChanges(); int id = eventModel.Event.Id; if (eventModel.UploadedImages[0] != null) { foreach (var img in eventModel.UploadedImages) { PhotoGallery.Models.Image imgObj = new PhotoGallery.Models.Image(); string filename = Path.GetFileNameWithoutExtension(img.FileName); string extension = Path.GetExtension(img.FileName); filename = filename + DateTime.Now.ToString("yymm") + extension; imgObj.Name = filename; string relative_path = "/Images/" + filename; imgObj.Path = relative_path; string filepath = Server.MapPath("~" + relative_path); imgObj.EventId = id; img.SaveAs(filepath); _context.Image.Add(imgObj); _context.SaveChanges(); } } return(RedirectToAction("Detail", new { id = id })); }