public Phocalstream_Shared.Data.Model.Photo.Photo ProcessPhoto(string fileName, CameraSite site) { string relativeName = fileName; fileName = Path.Combine(PathManager.GetRawPath(), fileName); FileInfo info = new FileInfo(fileName); try { // create the directory for the image and its components string basePath = Path.Combine(Path.Combine(PathManager.GetPhotoPath(), site.DirectoryName), string.Format("{0}.phocalstream", info.Name)); if (Directory.Exists(basePath) == false) { Directory.CreateDirectory(basePath); } // open a Bitmap for the image to parse the meta data from using (System.Drawing.Image img = System.Drawing.Image.FromFile(fileName)) { Photo photo = CreatePhotoWithProperties(img, info.Name); photo.Site = site; photo.FileName = relativeName; PhotoRepository.Insert(photo); // only generate the phocalstream image if it has not already been generated if (File.Exists(Path.Combine(basePath, @"High.jpg")) == false) { // this is a dirty hack, figure out why the image isn't opening with the correct width and height if (photo.Portrait) { photo.Width = img.Height; photo.Height = img.Width; } ResizeImageTo(fileName, 1200, 800, Path.Combine(basePath, @"High.jpg"), photo.Portrait); ResizeImageTo(fileName, 800, 533, Path.Combine(basePath, @"Medium.jpg"), photo.Portrait); ResizeImageTo(fileName, 400, 266, Path.Combine(basePath, @"Low.jpg"), photo.Portrait); } float[] percentages = ConvertCountsToPercentage(CountRGBPixels(new Bitmap(img))); photo.Black = percentages[(int)PixelColor.BLACK]; photo.White = percentages[(int)PixelColor.WHITE]; photo.Red = percentages[(int)PixelColor.RED]; photo.Green = percentages[(int)PixelColor.GREEN]; photo.Blue = percentages[(int)PixelColor.BLUE]; return(photo); } } catch (Exception e) { // this should be logged throw new Exception(string.Format("Exception processing photo {0}. Message: {1}", fileName, e.Message)); } }
public List <string> GetFileNames(List <Photo> photos) { List <string> fileNames = new List <string>(); foreach (Photo photo in photos) { Collection collection = CollectionRepository.Find(c => c.Site.ID == photo.Site.ID, c => c.Owner).FirstOrDefault(); if (collection.Type == CollectionType.SITE) { fileNames.Add(Path.Combine(PathManager.GetPhotoPath(), photo.Site.DirectoryName, string.Format("{0}.phocalstream", photo.BlobID), "Tiles.dzi")); } else if (collection.Type == CollectionType.USER) { fileNames.Add(Path.Combine(PathManager.GetUserCollectionPath(), Convert.ToString(collection.Owner.ID), photo.Site.DirectoryName, string.Format("{0}.phocalstream", photo.BlobID), "Tiles.dzi")); } } return(fileNames); }