public static Fotka AddPhotoTypeToPhoto(Fotka photo, TypFotky type) { var doSave = false; if(photo.TypyFotek == null) { photo.TypyFotek = new List<TypFotky>{type}; doSave = true; } else { if(photo.TypyFotek.All(p => p.SystemName.ToLower() != type.SystemName.ToLower())) { photo.TypyFotek.Add(type); doSave = true; } } if(doSave) { Save(photo); } return photo; }
public static void ResizeImage(Fotka fotka, TypFotky fromType, TypFotky targetType) { if(FotkaManager.FotkaTypExist(fotka, targetType)) { //TODO: double check photoType really exists on disk. return; } ResizeImage(fotka, fromType, targetType, null); }
public static string GetPhotoFullPath(Fotka fotka, TypFotky photoType) { if (fotka == null || photoType == null) { throw new ArgumentException("fotka nebo typ"); } if (fotka.TypyFotek != null && fotka.TypyFotek.Any(f => f.SystemName.ToLower() == photoType.SystemName.ToLower())) { var typeFolder = fotka.TypyFotek.First(f => f.SystemName.ToLower() == photoType.SystemName.ToLower()).Adresar; return HttpContext.Current.Server.MapPath(string.Format("{0}/{1}/{2}", fotka.BaseFotkaVirtualPath, typeFolder, fotka.NazevSouboru)); } throw new Exception(string.Format("U fotky id: {0} není definice originálu!", fotka.Id)); }
public static bool FotkaTypExist(Fotka fotka, TypFotky typ) { return fotka.TypyFotek.Any(tf => tf.Id == typ.Id); }
public static void Update(TypFotky updatedItem) { var originalItem = DbContext.Current.Single<TypFotky>(t => t.Id == updatedItem.Id); DbContext.Current.Update(originalItem, updatedItem); }
public static void Save(TypFotky typFotky) { DbContext.Current.Add(typFotky); }
public static void ResizeImage(Fotka fotka, TypFotky fromType, TypFotky targetType, string savePath) { var thumb = DoResizeImage(fotka, fromType, targetType); if(string.IsNullOrEmpty(savePath)) { SaveImage(thumb, fotka, targetType); } else { SaveImage(thumb, savePath, fotka.NazevSouboru); } }
private static void SaveImage(Bitmap thumbImage, Fotka fotka, TypFotky targetType) { var targetTypeDirectory = HttpContext.Current.Server.MapPath(string.Format(@"{0}\{1}", fotka.BaseFotkaVirtualPath, targetType.Adresar)); SaveImage(thumbImage, targetTypeDirectory, fotka.NazevSouboru); }
public static int[] GetImageDimensions(Fotka fotka, TypFotky photoType) { var fullPath = GetPhotoFullPath(fotka, photoType); return GetImageDimensions(fullPath); }
private static Bitmap DoResizeImage(Fotka fotka, TypFotky fromType, TypFotky targetType) { var fullPath = GetPhotoFullPath(fotka, 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; }