Fix tuto3 picture taken crash on all devices
A modification of the JavaCameraView is needed to avoid a crash when the app is exited. It is a good practice to remove the callback after the stopPreview method.
This commit is contained in:
parent
60bf018781
commit
bef6de9025
@ -179,6 +179,8 @@ public class JavaCameraView extends CameraBridgeViewBase implements PreviewCallb
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (mCamera != null) {
|
if (mCamera != null) {
|
||||||
mCamera.stopPreview();
|
mCamera.stopPreview();
|
||||||
|
mCamera.setPreviewCallback(null);
|
||||||
|
|
||||||
mCamera.release();
|
mCamera.release();
|
||||||
}
|
}
|
||||||
mCamera = null;
|
mCamera = null;
|
||||||
|
@ -57,8 +57,8 @@ public class Tutorial3View extends JavaCameraView implements PictureCallback {
|
|||||||
public void takePicture(final String fileName) {
|
public void takePicture(final String fileName) {
|
||||||
Log.i(TAG, "Taking picture");
|
Log.i(TAG, "Taking picture");
|
||||||
this.mPictureFileName = fileName;
|
this.mPictureFileName = fileName;
|
||||||
// Call to garbage collector to avoid bug http://code.opencv.org/issues/2961
|
// Clear up buffers to avoid bug http://code.opencv.org/issues/2961
|
||||||
System.gc();
|
mCamera.setPreviewCallback(null);
|
||||||
|
|
||||||
// PictureCallback is implemented by the current class
|
// PictureCallback is implemented by the current class
|
||||||
mCamera.takePicture(null, null, this);
|
mCamera.takePicture(null, null, this);
|
||||||
@ -69,6 +69,7 @@ public class Tutorial3View extends JavaCameraView implements PictureCallback {
|
|||||||
Log.i(TAG, "Saving a bitmap to file");
|
Log.i(TAG, "Saving a bitmap to file");
|
||||||
// The camera preview was automatically stopped. Start it again.
|
// The camera preview was automatically stopped. Start it again.
|
||||||
mCamera.startPreview();
|
mCamera.startPreview();
|
||||||
|
mCamera.setPreviewCallback(this);
|
||||||
|
|
||||||
// Write the image in a file (in jpeg format)
|
// Write the image in a file (in jpeg format)
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user