public Photo AddPhotoTypeToPhoto(Photo photo, PhotoType photoType) { var doSave = false; if(photo.PhotoTypes == null) { photo.PhotoTypes = new List<PhotoType>{photoType}; doSave = true; } else { if(photo.PhotoTypes.All(p => p.SystemName.ToLower() != photoType.SystemName.ToLower())) { photo.PhotoTypes.Add(photoType); doSave = true; } } if(doSave) { Save(photo); } return photo; }
public static void ResizeImage(Photo photo, PhotoType fromType, PhotoType targetType) { if(PhotoManager.PhotoTypeExist(photo, targetType)) { //TODO: double check photoType really exists on disk. return; } ResizeImage(photo, fromType, targetType, null); }
public static string GetPhotoFullPath(Photo photo, PhotoType photoType) { if (photo == null || photoType == null) { throw new ArgumentException("Missing Photo or PhotoType"); } if (photo.PhotoTypes != null && photo.PhotoTypes.Any(f => f.SystemName.ToLower() == photoType.SystemName.ToLower())) { var typeFolder = photo.PhotoTypes.First(f => f.SystemName.ToLower() == photoType.SystemName.ToLower()).Directory; return HttpContext.Current.Server.MapPath(string.Format("{0}/{1}/{2}", photo.BasePhotoVirtualPath, typeFolder, photo.FileName)); } throw new Exception(string.Format("Original photo not defined for Photo Id: {0}!", photo.Id)); }
public void Save(PhotoType photoType) { _photoTypes.Collection.Save(photoType); }
public static void ResizeImage(Photo photo, PhotoType fromType, PhotoType targetType, string savePath) { var thumb = DoResizeImage(photo, fromType, targetType); if(string.IsNullOrEmpty(savePath)) { SaveImage(thumb, photo, targetType); } else { SaveImage(thumb, savePath, photo.FileName); } }
private static void SaveImage(Bitmap thumbImage, Photo photo, PhotoType targetType) { var targetTypeDirectory = HttpContext.Current.Server.MapPath(string.Format(@"{0}\{1}", photo.BasePhotoVirtualPath, targetType.Directory)); SaveImage(thumbImage, targetTypeDirectory, photo.FileName); }
public static int[] GetImageDimensions(Photo photo, PhotoType photoType) { var fullPath = GetPhotoFullPath(photo, photoType); return GetImageDimensions(fullPath); }
private static Bitmap DoResizeImage(Photo photo, PhotoType fromType, PhotoType targetType) { var fullPath = GetPhotoFullPath(photo, fromType); var origImage = LoadImage(fullPath); int resX = targetType.X; int resY; float ratio; //obrazek na sirku nebo ctverec: if (origImage.Width >= origImage.Height) { ratio = (float)origImage.Height / (float)origImage.Width; resY = Convert.ToInt32(resX * ratio); } else //obrazek na vysku. { if(targetType.Y.HasValue) //mam zadanou vysku { resY = targetType.Y.Value; ratio = (float)origImage.Width / (float)origImage.Height; resX = Convert.ToInt32(resY * ratio); } else //pokud nemam zadanou vysku, musim to resizovat podle zadane sirky { ratio = (float)origImage.Height / (float)origImage.Width; resY = Convert.ToInt32(resX * ratio); } } var thumbImage = new Bitmap(resX, resY, origImage.PixelFormat); Graphics g = Graphics.FromImage(thumbImage); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.CompositingQuality = CompositingQuality.HighQuality; var oRectangle = new Rectangle(0, 0, resX, resY); g.DrawImage(origImage, oRectangle); if (resX < origImage.Width) { var si = new SharpeningImage(); si.Filter(thumbImage); } origImage.Dispose(); return thumbImage; }
public ActionResult PhotoTypeEdit(PhotoTypeEdit ptEdit) { if (ModelState.IsValid) { try { var photoType = new PhotoType() {Name = ptEdit.Name, Directory = ptEdit.Directory, SystemName = ptEdit.SystemName, X = ptEdit.X}; if(ptEdit.Y.HasValue) { photoType.Y = ptEdit.Y.Value; } if(!string.IsNullOrEmpty(ptEdit.PhotoTypeId)) { photoType.Id = ObjectId.Parse(ptEdit.PhotoTypeId); } if (string.IsNullOrEmpty(ptEdit.PhotoTypeId)) //INSERT { _photoTypeManager.Save(photoType); ptEdit.OKMessage = "Uložení nového typu proběhlo úspěšně."; } else //UPDATE { _photoTypeManager.Save(photoType); ptEdit.OKMessage = "Update typu proběhl úspěšně."; } } catch (Exception ex) { ptEdit.ErrorMessage = "Při ukládání typu fotky došlo k chybě: " + ex.Message; } } else { ptEdit.ErrorMessage = "Některá povinná položka není vyplněná."; } return View(ptEdit); }
public static bool PhotoTypeExist(Photo photo, PhotoType photoType) { return photo.PhotoTypes.Any(tf => tf.Id == photoType.Id); }
public Photo RemovePhotoTypeFromPhoto(Photo photo, PhotoType ptToBeRemoved) { if(photo.PhotoTypes != null) { if(photo.PhotoTypes.Any(pt => pt.Id == ptToBeRemoved.Id)) { photo.PhotoTypes.Remove(ptToBeRemoved); Save(photo); } } return photo; }