Sample Tutorial-5 improved

Aditional toasts added;
Exception handling improved;
Bitmap recycling added.
This commit is contained in:
Alexander Smorkalov 2012-11-30 18:41:46 +04:00
parent f6ca38a579
commit 22484872fa
2 changed files with 15 additions and 1 deletions

View File

@ -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<String> 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;
}
}

View File

@ -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();