Example #1
0
        private Photo CreatePhotoWithProperties(System.Drawing.Image img, string name)
        {
            // get image mea data
            PropertyItem[] propItems = img.PropertyItems;

            // create a new photo with a GUID id for the cloud blob
            Photo photo = new Photo();
            photo.BlobID = name;
            photo.Width = img.Width;
            photo.Height = img.Height;
            photo.AdditionalExifProperties = new List<MetaDatum>();

            photo.Portrait = false;

            // initialize the date to something so it doesn't break if the metadata doesn't have a date
            photo.Captured = DateTime.Now;

            // walk the image properties and set the appropriate fields on the image for the various meta data types (EXIF)
            int len = propItems.Length;
            for (var i = 0; i < len; i++)
            {
                PropertyItem propItem = propItems[i];

                switch (propItem.Id)
                {
                    case 0x112:
                        photo.Portrait = BitConverter.ToUInt16(propItem.Value, 0) == 6 ? true : false;

                        break;
                    case 0x829A: // Exposure Time
                        photo.ExposureTime = Convert.ToDouble(BitConverter.ToInt32(propItem.Value, 0)) / Convert.ToDouble(BitConverter.ToInt32(propItem.Value, 4));
                        photo.ShutterSpeed = String.Format("{0}/{1}", BitConverter.ToUInt32(propItem.Value, 0), BitConverter.ToUInt32(propItem.Value, 4));
                        break;
                    case 0x0132: // Date
                        string[] parts = System.Text.Encoding.ASCII.GetString(propItem.Value).Split(':', ' ');
                        int year = int.Parse(parts[0]);
                        int month = int.Parse(parts[1]);
                        int day = int.Parse(parts[2]);
                        int hour = int.Parse(parts[3]);
                        int minute = int.Parse(parts[4]);
                        int second = int.Parse(parts[5]);

                        photo.Captured = new DateTime(year, month, day, hour, minute, second);
                        break;
                    case 0x010F: // Manufacturer
                        photo.AdditionalExifProperties.Add(new MetaDatum()
                        {
                            Photo = photo,
                            Name = "Manufacturer",
                            Type = "EXIF",
                            Value = System.Text.Encoding.ASCII.GetString(propItem.Value)
                        });
                        break;
                    case 0x5090: // Luminance
                        photo.AdditionalExifProperties.Add(new MetaDatum()
                        {
                            Photo = photo,
                            Name = "White Balance",
                            Type = "EXIF",
                            Value = Convert.ToString(BitConverter.ToUInt16(propItem.Value, 0))
                        });
                        break;
                    case 0x5091: // Chrominance
                        photo.AdditionalExifProperties.Add(new MetaDatum()
                        {
                            Photo = photo,
                            Name = "Color Space",
                            Type = "EXIF",
                            Value = Convert.ToString(BitConverter.ToUInt16(propItem.Value, 0))
                        });
                        break;
                    case 0x9205: // Max Aperture
                        photo.MaxAperture = Convert.ToDouble(BitConverter.ToInt32(propItem.Value, 0)) / Convert.ToDouble(BitConverter.ToInt32(propItem.Value, 4));
                        break;
                    case 0x920A: // Focal Length
                        photo.FocalLength = BitConverter.ToInt32(propItem.Value, 0) / BitConverter.ToInt32(propItem.Value, 4);
                        break;
                    case 0x9209: // Flash
                        photo.Flash = Convert.ToBoolean(BitConverter.ToUInt16(propItem.Value, 0));
                        break;
                    case 0x9286: // Comment
                        photo.UserComments = System.Text.Encoding.ASCII.GetString(propItem.Value);
                        break;
                    case 0x8827: // ISO Speed
                        photo.ISO = BitConverter.ToUInt16(propItem.Value, 0);
                        break;
                }
            }

            return photo;
        }
Example #2
0
        public List<Photo> GetPhotoRangeForCollection(long collectionID, int startIndex, int length)
        {
            List<Photo> photos = new List<Photo>();
            using (SqlConnection conn = new SqlConnection(_connectionString))
            {
                conn.Open();
                string command_string = "select Photos.ID, Photos.Captured FROM Photos " +
                    "INNER JOIN CollectionPhotos ON Photos.ID = CollectionPhotos.PhotoId " +
                    "WHERE CollectionPhotos.CollectionId = @collectionID " +
                    "ORDER BY Photos.ID " +
                    "OFFSET @offset ROWS FETCH NEXT @length ROWS ONLY";

                using (SqlCommand command = new SqlCommand(command_string, conn))
                {
                    command.Parameters.AddWithValue("@collectionID", collectionID);
                    command.Parameters.AddWithValue("@offset", startIndex);
                    command.Parameters.AddWithValue("@length", length);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Photo photo = new Photo()
                            {
                                ID = reader.GetInt64(0),
                                Captured = reader.GetDateTime(1)
                            };
                            photos.Add(photo);
                        }
                    }
                }
            }
            return photos;
        }