public static async Task<Picture> GetPictureDetails(StorageFile file) { if (file == null) return null; //get image BitmapImage image = await GetImageFromStorageFile(file); //get GPS coordinates var imageProperties = await file.Properties.GetImagePropertiesAsync(); string imageLatitude = ""; string imageLongitude = ""; string latRefText, longRefText, latDegText, latMinText, latSecText, longDegText, longMinText, longSecText; if ((imageProperties.Latitude.HasValue) && (imageProperties.Longitude.HasValue)) { double latitude = imageProperties.Latitude.Value; double longitude = imageProperties.Longitude.Value; latRefText = (latitude >= 0) ? "N" : "S"; longRefText = (longitude >= 0) ? "E" : "W"; double latDeg = Math.Floor(Math.Abs(latitude)); latDegText = latDeg.ToString().TruncateLongString(2); double latMin = Math.Floor((Math.Abs(latitude) - latDeg) * 60); latMinText = latMin.ToString().TruncateLongString(2); latSecText = ((Math.Abs(latitude) - latDeg - latMin / 60) * 3600).ToString().TruncateLongString(7); double longDeg = Math.Floor(Math.Abs(longitude)); longDegText = longDeg.ToString().TruncateLongString(2); double longMin = Math.Floor((Math.Abs(longitude) - longDeg) * 60); longMinText = longMin.ToString().TruncateLongString(2); longSecText = ((Math.Abs(longitude) - longDeg - longMin / 60) * 3600).ToString().TruncateLongString(7); imageLatitude = latDegText + "° " + latMinText + "\" " + latSecText + "' " + latRefText; imageLongitude = longDegText + "° " + longMinText + "\" " + longSecText + "' " + longRefText; } //get exposure and white balance string[] requests = { "System.Photo.ExposureTime", "System.Photo.WhiteBalance" }; IDictionary<string, object> retrievedProps = await imageProperties.RetrievePropertiesAsync(requests); string exposure = ""; if (retrievedProps.ContainsKey("System.Photo.ExposureTime")) { exposure = ((double)retrievedProps["System.Photo.ExposureTime"] * 1000).ToString() + " ms"; } string whiteBalance = ""; if (retrievedProps.ContainsKey("System.Photo.WhiteBalance")) { whiteBalance = (retrievedProps["System.Photo.WhiteBalance"]).ToString(); } //get orientation string orientation = ""; switch (imageProperties.Orientation) { case PhotoOrientation.FlipHorizontal: orientation = "odbicie horyzontalne"; break; case PhotoOrientation.FlipVertical: orientation = "odbicie wertykalne"; break; case PhotoOrientation.Normal: orientation = "normalna"; break; case PhotoOrientation.Rotate180: orientation = "obrót 180 stopni"; break; case PhotoOrientation.Rotate270: orientation = "obrót 270 stopni"; break; case PhotoOrientation.Rotate90: orientation = "obrót 90 stopni"; break; case PhotoOrientation.Transpose: orientation = "transpozycja"; break; case PhotoOrientation.Transverse: orientation = "poprzeczna"; break; case PhotoOrientation.Unspecified: orientation = "nieokreślona"; break; } //create picture Picture picture = new Picture { Title = file.DisplayName, Image = image, Path = file.Path, Name = file.Name, Type = file.DisplayType, DateTaken = imageProperties.DateTaken.ToString(), Orientation = orientation, CameraModel = imageProperties.CameraModel, Latitude = imageLatitude, Longitude = imageLongitude, Exposure = exposure, WhiteBalance = whiteBalance }; return picture; }
protected override async void OnNavigatedTo(NavigationEventArgs e) { Picture = new Picture(); Picture = await ImageManager.GetPictureDetails((StorageFile)e.Parameter); }