void SetMissingMetadata(ExifInterface exif, Location location) { if (exif == null) { return; } var position = new float[6]; if (!exif.GetLatLong(position) && location != null) { exif.SetAttribute(ExifInterface.TagGpsLatitude, CoordinateToRational(location.Latitude)); exif.SetAttribute(ExifInterface.TagGpsLongitude, CoordinateToRational(location.Longitude)); exif.SetAttribute(ExifInterface.TagGpsLatitudeRef, location.Latitude > 0 ? "N" : "S"); exif.SetAttribute(ExifInterface.TagGpsLongitudeRef, location.Longitude > 0 ? "E" : "W"); } if (string.IsNullOrEmpty(exif.GetAttribute(ExifInterface.TagDatetime))) { exif.SetAttribute(ExifInterface.TagDatetime, DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss")); } if (string.IsNullOrEmpty(exif.GetAttribute(ExifInterface.TagMake))) { exif.SetAttribute(ExifInterface.TagMake, Build.Manufacturer); } if (string.IsNullOrEmpty(exif.GetAttribute(ExifInterface.TagModel))) { exif.SetAttribute(ExifInterface.TagModel, Build.Model); } }
public static Location ReadLocation(this ExifInterface exif) { var pos = new float[2]; if (exif.GetLatLong(pos)) { var date = exif.GetAttribute(ExifInterface.TagDatetime); var time = ExifFormat.Parse(date).Time; return(new Location("exif") { Latitude = pos[0], Longitude = pos[1], Time = time }); } return(null); }
void SetMissingMetadata(ExifInterface exif, Location location) { var exifPos = exif.GetLatLong(); if (exifPos == null && location != null && location.Latitude != null && location.Longitude != null) { exif.SetLatLong((double)location.Latitude, (double)location.Longitude); } if (string.IsNullOrEmpty(exif.GetAttribute(ExifInterface.TagDatetime))) { exif.SetAttribute(ExifInterface.TagDatetime, DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss")); exif.SetAttribute(ExifInterface.TagDatetimeOriginal, DateTime.Now.ToString("yyyy:MM:dd hh:mm:ss")); } if (string.IsNullOrEmpty(exif.GetAttribute(ExifInterface.TagMake))) { exif.SetAttribute(ExifInterface.TagMake, Build.Manufacturer); } if (string.IsNullOrEmpty(exif.GetAttribute(ExifInterface.TagModel))) { exif.SetAttribute(ExifInterface.TagModel, Build.Model); } }
public override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == Result.Ok) { // Make it available in the gallery // Intent mediaScanIntent = new Intent (Intent.ActionMediaScannerScanFile); // Android.Net.Uri contentUri = Android.Net.Uri.FromFile (file); // mediaScanIntent.SetData (contentUri); // // Activity.SendBroadcast (mediaScanIntent); // AttendancePhoto attPhoto = new AttendancePhoto() { photoPath = file.ToString(), stamp = DateTime.Now, subType = currentPhotoSubTypes[spnPhotoSubTypes.SelectedItemPosition].id }; //Latitude and Longitude ExifInterface exif = new ExifInterface(attPhoto.photoPath); float[] lat_long = new float[2]; if (exif.GetLatLong(lat_long)) { attPhoto.latitude = lat_long [0]; attPhoto.longitude = lat_long [1]; } newAttendancePhotos.Add(attPhoto); AttendancePhotoManager.SetCurrentAttendancePhotos(newAttendancePhotos); RefreshPhotoList(); } // Dispose of the Java side bitmap. GC.Collect(); }
public override void OnActivityResult(int requestCode, int resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if ((requestCode == C_REQUEST_PHOTO) && (resultCode == -1)) { //var trans = MainDatabase.BeginTransaction(); var photo = new PhotoData(); //MainDatabase.CreatePhoto(); photo.Stamp = DateTimeOffset.Now; photo.PhotoPath = File.ToString(); var photoType = PhotoTypes[PhotoType.SelectedItemPosition]; photo.PhotoType = photoType.uuid; if (photoType.isNeedBrand) { photo.Brand = Brands[Brand.SelectedItemPosition - 1].uuid; } //Latitude and Longitudee var exif = new ExifInterface(photo.PhotoPath); float[] latLong = new float[2]; if (exif.GetLatLong(latLong)) { photo.Latitude = latLong[0]; photo.Longitude = latLong[1]; } Photos.Add(photo); //trans.Commit(); RefreshPhotoList(); } // Dispose of the Java side bitmap. GC.Collect(); }