Наследование: IImageProperties, IStorageItemExtraProperties
Пример #1
0
 public PhotoModel(BitmapImage photo, string path, BitmapImage thumbnailImage, ImageProperties properties, StorageFile storageFile)
 {
     Photo = photo;
     Path = path;
     ThumbnailImage = thumbnailImage;
     Properties = properties;
     StorageFile = storageFile;
 }
Пример #2
0
        public static void FillImageProperties(PropertiesFlyoutImage flyout, ImageProperties imageProps, StorageFile file, BasicProperties basicProps)
        {
            try
            {
                if (imageProps.DateTaken.Year > 1700)
                    flyout.DateTaken.Text = DateTime_ToString(imageProps.DateTaken, EDateTimeFormat.G);
                else if (basicProps != null)
                    flyout.DateTaken.Text = DateTime_ToString(basicProps.DateModified, EDateTimeFormat.G);
                else
                    flyout.DateTaken.Visibility = Visibility.Collapsed;

                if (imageProps.Width > 0 && imageProps.Height > 0)
                    flyout.Dimensions.Text = imageProps.Width.ToString() + " x " + imageProps.Height.ToString() + " pixels";
                else
                    flyout.Dimensions.Visibility = Visibility.Collapsed;

                // IMPORTANT: Need GeoCoordinate class from System.Device.Location namespace (but not avail on WinRT);
                // Not suitable: Windows.Devices.Geolocation namespace;
                // GeoCoordinate geoCoord = new GeoCoordinate();
                if (imageProps.Latitude.HasValue)
                    flyout.Latitude.Text = Util.LatOrLong_ToString(imageProps.Latitude);
                else
                    flyout.Latitude.Visibility = Visibility.Collapsed;
                if (imageProps.Longitude.HasValue)
                    flyout.Longitude.Text = Util.LatOrLong_ToString(imageProps.Longitude);
                else
                    flyout.Longitude.Visibility = Visibility.Collapsed;

                if (!string.IsNullOrEmpty(imageProps.Title))
                    flyout.ImgTitle.Text = imageProps.Title;
                else
                    flyout.ImgTitle.Visibility = Visibility.Collapsed;

                if (!string.IsNullOrEmpty(imageProps.CameraManufacturer))
                {
                    flyout.Camera.Text = imageProps.CameraManufacturer;
                    if (!string.IsNullOrEmpty(imageProps.CameraModel))
                        flyout.Camera.Text += " " + imageProps.CameraModel;
                }
                else
                    flyout.Camera.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex) { Debug.WriteLine(ex.ToString()); }
        }
            private static string GetImageDetails(ImageProperties properties)
            {
                var data = "";

                var title = Path.GetFileName(properties.Title);
                data += ("Title: " + title);
                var dateTaken = properties.DateTaken;
                data += ("\tDate taken: " + dateTaken);
                var width = Convert.ToString(properties.Width);
                if(width != null)
                    data += ("\nWidth: " + width);
                var height = Convert.ToString(properties.Height);
                if(height != null)
                    data += ("\tHeight: " + height);
                var latitude = Convert.ToString(properties.Latitude);
                if (latitude != null)
                    data += ("\nLatitude: " + latitude);
                var longitude = Convert.ToString(properties.Longitude);
                if (longitude != null)
                    data += ("\tLongitude: " + longitude);
                var cameraModel = properties.CameraModel;
                data += ("\nCamera model: " + cameraModel);
                var cameraManufacture = properties.CameraManufacturer;
                data += ("\tCamera manufacture: " + cameraManufacture);

                return data;
            }
        /// <summary>
        /// Clears all of the state that is stored in memory and in the UI.
        /// </summary>
        private void ResetSessionState()
        {
            m_imageProperties = null;
            m_fileToken = null;

            CloseButton.IsEnabled = false;
            ApplyButton.IsEnabled = false;
            PreviewImage.Source = null;

            TitleTextbox.Text = "";
            KeywordsTextbox.Text = "";
            DateTakenTextblock.Text = "";
            MakeTextblock.Text = "";
            ModelTextblock.Text = "";
            OrientationTextblock.Text = "";
            LatDegTextbox.Text = "";
            LatMinTextbox.Text = "";
            LatSecTextbox.Text = "";
            LatRefTextbox.Text = "";
            LongDegTextbox.Text = "";
            LongMinTextbox.Text = "";
            LongSecTextbox.Text = "";
            LongRefTextbox.Text = "";
            ExposureTextblock.Text = "";
            FNumberTextblock.Text = "";
        }
        /// <summary>
        /// Load an image from a file and display some basic imaging properties.
        /// </summary>
        /// <param name="file">The image to load.</param>
        private async Task LoadFileAsync(StorageFile file)
        {
            try
            {
                // Request persisted access permissions to the file the user selected.
                // This allows the app to directly load the file in the future without relying on a
                // broker such as the file picker.
                m_fileToken = m_futureAccess.Add(file);

                // Windows.Storage.FileProperties.ImageProperties provides convenience access to
                // commonly-used properties such as geolocation and keywords. It also accepts
                // queries for Windows property system keys such as "System.Photo.Aperture".
                m_imageProperties = await file.Properties.GetImagePropertiesAsync();

                string[] requests =
                {
                    "System.Photo.ExposureTime",        // In seconds
                    "System.Photo.FNumber"              // F-stop values defined by EXIF spec
                };

                IDictionary<string, object> retrievedProps =
                    await m_imageProperties.RetrievePropertiesAsync(requests);
                await DisplayImageUIAsync(file, GetImagePropertiesForDisplay(retrievedProps));

                rootPage.NotifyUser(
                    "Loaded file from picker: " + file.Name,
                    NotifyType.StatusMessage
                    );

                CloseButton.IsEnabled = true;
                ApplyButton.IsEnabled = true;
            }
            catch (Exception err)
            {
                rootPage.NotifyUser("Error: " + err.Message, NotifyType.ErrorMessage);
                ResetPersistedState();
                ResetSessionState();
            }
        }
        /// <summary>
        /// Reads the file token and property text from the persisted state, and calls
        /// DisplayImageUIAsync().
        /// </summary>
        private async void RestoreDataFromPersistedState()
        {
            try
            {
                m_fileToken = m_localSettings["scenario1FileToken"].ToString();
                StorageFile file = await m_futureAccess.GetFileAsync(m_fileToken);
                m_imageProperties = await file.Properties.GetImagePropertiesAsync();

                Dictionary<string, string> propertyText = new Dictionary<string, string>();
                propertyText.Add("Title", m_localSettings["scenario1Title"].ToString());
                propertyText.Add("Keywords", m_localSettings["scenario1Keywords"].ToString());
                propertyText.Add("DateTaken", m_localSettings["scenario1DateTaken"].ToString());
                propertyText.Add("Make", m_localSettings["scenario1Make"].ToString());
                propertyText.Add("Model", m_localSettings["scenario1Model"].ToString());
                propertyText.Add("Orientation", m_localSettings["scenario1Orientation"].ToString());
                propertyText.Add("LatDeg", m_localSettings["scenario1LatDeg"].ToString());
                propertyText.Add("LatMin", m_localSettings["scenario1LatMin"].ToString());
                propertyText.Add("LatSec", m_localSettings["scenario1LatSec"].ToString());
                propertyText.Add("LatRef", m_localSettings["scenario1LatRef"].ToString());
                propertyText.Add("LongDeg", m_localSettings["scenario1LongDeg"].ToString());
                propertyText.Add("LongMin", m_localSettings["scenario1LongMin"].ToString());
                propertyText.Add("LongSec", m_localSettings["scenario1LongSec"].ToString());
                propertyText.Add("LongRef", m_localSettings["scenario1LongRef"].ToString());
                propertyText.Add("Exposure", m_localSettings["scenario1Exposure"].ToString());
                propertyText.Add("FNumber", m_localSettings["scenario1FNumber"].ToString());

                await DisplayImageUIAsync(file, propertyText);

                rootPage.NotifyUser(
                    "Loaded file from persisted state: " + file.Name,
                    NotifyType.StatusMessage
                    );

                CloseButton.IsEnabled = true;
                ApplyButton.IsEnabled = true;
            }
            catch (Exception err)
            {
                rootPage.NotifyUser("Error: " + err.Message, NotifyType.ErrorMessage);
                ResetSessionState();
                ResetPersistedState();
            }
        }
Пример #7
0
        /// <summary>
        /// Clear all of the state that is stored in memory and in the UI.
        /// </summary>
        private async void ResetSessionState()
        {
            m_imageProperties = null;
            m_fileToken = null;

            CloseButton.IsEnabled = false;
            ApplyButton.IsEnabled = false;

            StorageFile placeholderImage = await Package.Current.InstalledLocation.GetFileAsync("Assets\\placeholder-sdk.png");
            BitmapImage bitmapImage = new BitmapImage();
            using (IRandomAccessStream stream = await placeholderImage.OpenAsync(FileAccessMode.Read))
            {
                await bitmapImage.SetSourceAsync(stream);
            }
                Image1.Source = bitmapImage;
            AutomationProperties.SetName(Image1, "A placeholder image");

            TitleTextbox.Text = "";
            KeywordsTextbox.Text = "";
            DateTakenTextblock.Text = "";
            MakeTextblock.Text = "";
            ModelTextblock.Text = "";
            OrientationTextblock.Text = "";
            LatDegTextbox.Text = "";
            LatMinTextbox.Text = "";
            LatSecTextbox.Text = "";
            LatRefTextbox.Text = "";
            LongDegTextbox.Text = "";
            LongMinTextbox.Text = "";
            LongSecTextbox.Text = "";
            LongRefTextbox.Text = "";
            ExposureTextblock.Text = "";
            FNumberTextblock.Text = "";
        }
        private static void GetImageProperties(ICollection<StorageFileProperty> results, ImageProperties props)
        {
            var title = props.Title;
            var dateTaken = props.DateTaken.ToString("G");

            var manufacturer = props.CameraManufacturer;
            var model = props.CameraModel;

            var height = props.Height;
            var width = props.Width;

            var latitude = props.Latitude.ToString();
            var longitude = props.Longitude.ToString();

            if (!title.IsEmpty())
            {
                if (results.FirstOrDefault(x => x.Name == "Title") == null)
                {
                    results.Add(new StorageFileProperty("Title", title));
                }
            }

            if (!dateTaken.IsEmpty())
            {
                if (dateTaken.IsValidDate())
                {
                    if (results.FirstOrDefault(x => x.Name == "Date Taken") == null)
                    {
                        results.Add(new StorageFileProperty("Date Taken", dateTaken));
                    }
                }
            }

            if (!manufacturer.IsEmpty())
            {
                if (results.FirstOrDefault(x => x.Name == "Manufacturer") == null)
                {
                    results.Add(new StorageFileProperty("Manufacturer", manufacturer));
                }
            }

            if (!model.IsEmpty())
            {
                if (results.FirstOrDefault(x => x.Name == "Model") == null)
                {
                    results.Add(new StorageFileProperty("Model", model));
                }
            }

            if (height != 0 || width != 0)
            {
                if (results.FirstOrDefault(x => x.Name == "Height") == null)
                {
                    results.Add(new StorageFileProperty("Height", height));
                }

                if (results.FirstOrDefault(x => x.Name == "Width") == null)
                {
                    results.Add(new StorageFileProperty("Width", width));
                }
            }


            if (!latitude.IsEmpty())
            {
                if (results.FirstOrDefault(x => x.Name == "GPS latitude") == null)
                {
                    results.Add(new StorageFileProperty("GPS latitude", latitude));
                }
            }

            if (!longitude.IsEmpty())
            {
                if (results.FirstOrDefault(x => x.Name == "GPS longitude") == null)
                {
                    results.Add(new StorageFileProperty("GPS longitude", longitude));
                }
            }
        }
Пример #9
0
        private string generateInformations(ImageProperties props)
        {
            string infos = "PICTURE INFORMATIONS: ";
            if (!string.IsNullOrEmpty(props.CameraManufacturer))
                infos += "\nCameraManufacturer: " + props.CameraManufacturer;
            if (!string.IsNullOrEmpty(props.CameraModel))
                infos += "\nCameraModel: " + props.CameraModel;
            if (!string.IsNullOrEmpty(props.Title))
                infos += "\nTitle: " + props.Title;
            if (props.Width != 0)
                infos += "\nWidth: " + props.Width;
            if (props.Height != 0)
                infos += "\nHeight: " + props.Height;
            DateTimeOffset? tempDate = props.DateTaken;
            if (tempDate != null)
                infos += "\nDate taken: " + Convert.ToString(props.DateTaken);
            if (props.Latitude != null)
                infos += "\nLatitude: " + Convert.ToString(props.Latitude);
            if (props.Longitude != null)
                infos += "\nLongitude: " + Convert.ToString(props.Longitude);

            return infos;
        }