Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        public Photo ProcessRGBForExistingPhoto(long photoID)
        {
            Photo photo = PhotoRepository.Single(p => p.ID == photoID);

            if (photo == null)
            {
                return(null);
            }

            using (System.Drawing.Bitmap bitmap = new Bitmap(System.Drawing.Image.FromFile(string.Format("{0}{1}", PathManager.GetRawPath(), photo.FileName))))
            {
                int[]   counts      = CountRGBPixels(bitmap);
                float[] percentages = ConvertCountsToPercentage(counts);

                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);
            }
        }