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 void OnPictureTaken(byte[] data, Android.Hardware.Camera camera) { FileOutputStream output = null; string path = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments), "Images"); if (!System.IO.Directory.Exists(path)) System.IO.Directory.CreateDirectory(path); string filename = PictureName + number.ToString() + ".jpg"; if (data != null) { fullFilename = System.IO.Path.Combine(path, filename); number++; try { output = new FileOutputStream(fullFilename); output.Write(data); output.Close(); } catch (FileNotFoundException) { RunOnUiThread(delegate { GeneralUtils.Alert(context, Application.Context.Resources.GetString(Resource.String.commonError), Application.Context.Resources.GetString(Resource.String.errorFileTransfer)); }); return; } catch (IOException) { RunOnUiThread(delegate { GeneralUtils.Alert(context, Application.Context.Resources.GetString(Resource.String.commonError), Application.Context.Resources.GetString(Resource.String.errorNoImagesTaken)); }); isRunning = true; camera.StartPreview(); return; } catch (Exception e) { #if DEBUG System.Diagnostics.Debug.WriteLine("Exception thrown - {0}", e.Message); #endif return; } var f = new File(fullFilename); try { var exifInterface = new ExifInterface(f.CanonicalPath); exifInterface.GetAttribute(ExifInterface.TagModel); var latLong = new float[2]; exifInterface.GetLatLong(latLong); exifInterface.SetAttribute(ExifInterface.TagMake, "Phone picture"); exifInterface.SetAttribute(ExifInterface.TagDatetime, DateTime.Now.ToString()); } catch (IOException) { RunOnUiThread(delegate { GeneralUtils.Alert(context, Application.Context.Resources.GetString(Resource.String.commonError), Application.Context.Resources.GetString(Resource.String.errorStoreEXIF)); }); isRunning = true; camera.StartPreview(); return; } } RunOnUiThread(() => Toast.MakeText(context, Application.Context.Resources.GetString(Resource.String.commonPictureTaken), ToastLength.Short).Show()); isRunning = true; camera.StartPreview(); return; }