From 22484872fa7b875b7ba98760d5256bbe46557369 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Fri, 30 Nov 2012 18:41:46 +0400 Subject: [PATCH] Sample Tutorial-5 improved Aditional toasts added; Exception handling improved; Bitmap recycling added. --- .../samples/tutorial5/Sample5CameraControl.java | 11 ++++++++++- .../samples/tutorial5/SampleJavaCameraView.java | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java index 358d527b98..38b6dd7b78 100644 --- a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java +++ b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/Sample5CameraControl.java @@ -20,6 +20,7 @@ import android.view.SurfaceView; import android.view.View; import android.view.View.OnTouchListener; import android.view.WindowManager; +import android.widget.Toast; public class Sample5CameraControl extends Activity implements CvCameraViewListener, OnTouchListener { private static final String TAG = "OCVSample::Activity"; @@ -100,6 +101,11 @@ public class Sample5CameraControl extends Activity implements CvCameraViewListen public boolean onCreateOptionsMenu(Menu menu) { List effects = mOpenCvCameraView.getEffectList(); + if (effects == null) { + Log.e(TAG, "Color effects are not supported by device!"); + return true; + } + mEffectMenuItems = new MenuItem[effects.size()]; int idx = 0; @@ -115,13 +121,16 @@ public class Sample5CameraControl extends Activity implements CvCameraViewListen public boolean onOptionsItemSelected(MenuItem item) { Log.i(TAG, "called onOptionsItemSelected; selected item: " + item); mOpenCvCameraView.setEffect((String) item.getTitle()); + Toast.makeText(this, mOpenCvCameraView.getEffect(), Toast.LENGTH_SHORT).show(); return true; } @Override public boolean onTouch(View v, MotionEvent event) { Log.i(TAG,"onTouch event"); - mOpenCvCameraView.takePicture(Environment.getExternalStorageDirectory().getPath() + "/sample_picture.jpg"); + String fileName = Environment.getExternalStorageDirectory().getPath() + "/sample_picture.jpg"; + mOpenCvCameraView.takePicture(fileName); + Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show(); return false; } } diff --git a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/SampleJavaCameraView.java b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/SampleJavaCameraView.java index fa33b8f4b7..8cbf312ba9 100644 --- a/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/SampleJavaCameraView.java +++ b/samples/android/tutorial-5-cameracontrol/src/org/opencv/samples/tutorial5/SampleJavaCameraView.java @@ -25,6 +25,10 @@ public class SampleJavaCameraView extends JavaCameraView { return mCamera.getParameters().getSupportedColorEffects(); } + public boolean isEffectSupported() { + return (mCamera.getParameters().getColorEffect() != null); + } + public String getEffect() { return mCamera.getParameters().getColorEffect(); } @@ -48,6 +52,7 @@ public class SampleJavaCameraView extends JavaCameraView { try { FileOutputStream out = new FileOutputStream(mPictureFileName); picture.compress(Bitmap.CompressFormat.JPEG, 90, out); + picture.recycle(); mCamera.startPreview(); } catch (Exception e) { e.printStackTrace(); -- 2.34.1