public void PictureTaken(object sender, ProcessedCameraPreview.PictureTakenEventArgs ea) { Android.Graphics.Bitmap bmp = ea.Bitmap; Camera camera = ea.Camera; try { Android.Graphics.Bitmap thumbnail = null; int maxThumbnailSize = 96; if (_imageFilter == null) { _lastSavedImageFile = ProcessedCameraPreview.SaveBitmap(this, bmp, PackageName, _topLayer); thumbnail = ProcessedCameraPreview.GetThumbnail(bmp, maxThumbnailSize); bmp.Dispose(); } else { Image <Bgr, Byte> buffer1 = new Image <Bgr, byte>(bmp); bmp.Dispose(); using (ImageFilter filter = _imageFilter.Clone() as ImageFilter) { if (filter is DistorFilter) { //reduce the image size to half because the distor filter used lots of memory Image <Bgr, Byte> tmp = buffer1.PyrDown(); buffer1.Dispose(); buffer1 = tmp; } if (filter.InplaceCapable) { filter.ProcessData(buffer1.Mat, buffer1.Mat); } else { Image <Bgr, Byte> buffer2 = new Image <Bgr, byte>(buffer1.Size); filter.ProcessData(buffer1.Mat, buffer2.Mat); buffer1.Dispose(); buffer1 = buffer2; } } using (Android.Graphics.Bitmap result = buffer1.ToBitmap()) { buffer1.Dispose(); _lastSavedImageFile = ProcessedCameraPreview.SaveBitmap(this, result, PackageName, _topLayer); thumbnail = ProcessedCameraPreview.GetThumbnail(result, maxThumbnailSize); } } _lastCapturedImageButton.SetImageBitmap(thumbnail); } catch (Exception excpt) { this.RunOnUiThread(() => { while (excpt.InnerException != null) { excpt = excpt.InnerException; } AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.SetTitle("Error saving file"); alert.SetMessage(excpt.Message); alert.SetPositiveButton("OK", (s, er) => { }); alert.Show(); }); return; } /* * catch (FileNotFoundException e) * { * Android.Util.Log.Debug("Emgu.CV", e.Message); * } * catch (IOException e) * { * Android.Util.Log.Debug("Emgu.CV", e.Message); * } */ /* * try * { * ExifInterface exif = new ExifInterface(f.FullName); * // Read the camera model and location attributes * exif.GetAttribute(ExifInterface.TagModel); * float[] latLng = new float[2]; * exif.GetLatLong(latLng); * // Set the camera make * exif.SetAttribute(ExifInterface.TagMake, "My Phone"); * exif.SetAttribute(ExifInterface.TagDatetime, System.DateTime.Now.ToString()); * } * catch (IOException e) * { * Android.Util.Log.Debug("Emgu.CV", e.Message); * }*/ Toast.MakeText(this, "File Saved.", ToastLength.Short).Show(); camera.StartPreview(); }