diff --git a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java b/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java index 147393a839..376c86adb1 100644 --- a/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java +++ b/samples/android/tutorial-0-androidcamera/src/org/opencv/samples/tutorial0/SampleViewBase.java @@ -25,6 +25,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde private byte[] mFrame; private boolean mThreadRun; private byte[] mBuffer; + private SurfaceTexture mSf; public SampleViewBase(Context context) { @@ -43,16 +44,17 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde } public void setPreview() throws IOException { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) - mCamera.setPreviewTexture( new SurfaceTexture(10) ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mSf = new SurfaceTexture(10); + mCamera.setPreviewTexture( mSf ); + } else - mCamera.setPreviewDisplay(null); + mCamera.setPreviewDisplay(null); } public boolean openCamera() { Log.i(TAG, "openCamera"); - releaseCamera(); mCamera = Camera.open(); if(mCamera == null) { Log.e(TAG, "Can't open camera!"); @@ -125,15 +127,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde mFrame = new byte [size]; mCamera.addCallbackBuffer(mBuffer); + /* Notify that the preview is about to be started and deliver preview size */ + onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); + try { setPreview(); } catch (IOException e) { Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); } - /* Notify that the preview is about to be started and deliver preview size */ - onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); - /* Now we can start a preview */ mCamera.startPreview(); } diff --git a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/SampleViewBase.java b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/SampleViewBase.java index d479215a7b..6151eb0957 100644 --- a/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/SampleViewBase.java +++ b/samples/android/tutorial-1-addopencv/src/org/opencv/samples/tutorial1/SampleViewBase.java @@ -25,6 +25,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde private byte[] mFrame; private boolean mThreadRun; private byte[] mBuffer; + private SurfaceTexture mSf; public SampleViewBase(Context context) { @@ -43,8 +44,10 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde } public void setPreview() throws IOException { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) - mCamera.setPreviewTexture( new SurfaceTexture(10) ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mSf = new SurfaceTexture(10); + mCamera.setPreviewTexture( mSf ); + } else mCamera.setPreviewDisplay(null); } @@ -124,15 +127,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde mFrame = new byte [size]; mCamera.addCallbackBuffer(mBuffer); + /* Notify that the preview is about to be started and deliver preview size */ + onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); + try { setPreview(); } catch (IOException e) { Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); } - /* Notify that the preview is about to be started and deliver preview size */ - onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); - /* Now we can start a preview */ mCamera.startPreview(); } diff --git a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/SampleViewBase.java b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/SampleViewBase.java index ac1762a8a0..f4666ed390 100644 --- a/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/SampleViewBase.java +++ b/samples/android/tutorial-3-native/src/org/opencv/samples/tutorial3/SampleViewBase.java @@ -24,6 +24,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde private byte[] mFrame; private boolean mThreadRun; private byte[] mBuffer; + private SurfaceTexture mSf; public SampleViewBase(Context context) { @@ -42,8 +43,10 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde } public void setPreview() throws IOException { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) - mCamera.setPreviewTexture( new SurfaceTexture(10) ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mSf = new SurfaceTexture(10); + mCamera.setPreviewTexture( mSf ); + } else mCamera.setPreviewDisplay(null); } @@ -123,15 +126,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde mFrame = new byte [size]; mCamera.addCallbackBuffer(mBuffer); + /* Notify that the preview is about to be started and deliver preview size */ + onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); + try { setPreview(); } catch (IOException e) { Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); } - /* Notify that the preview is about to be started and deliver preview size */ - onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); - /* Now we can start a preview */ mCamera.startPreview(); } diff --git a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/SampleViewBase.java b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/SampleViewBase.java index 4dafeddd69..4991e3033d 100644 --- a/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/SampleViewBase.java +++ b/samples/android/tutorial-4-mixed/src/org/opencv/samples/tutorial4/SampleViewBase.java @@ -24,6 +24,7 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde private byte[] mFrame; private boolean mThreadRun; private byte[] mBuffer; + private SurfaceTexture mSf; public SampleViewBase(Context context) { @@ -42,8 +43,10 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde } public void setPreview() throws IOException { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) - mCamera.setPreviewTexture( new SurfaceTexture(10) ); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + mSf = new SurfaceTexture(10); + mCamera.setPreviewTexture( mSf ); + } else mCamera.setPreviewDisplay(null); } @@ -123,15 +126,15 @@ public abstract class SampleViewBase extends SurfaceView implements SurfaceHolde mFrame = new byte [size]; mCamera.addCallbackBuffer(mBuffer); + /* Notify that the preview is about to be started and deliver preview size */ + onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); + try { setPreview(); } catch (IOException e) { Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e); } - /* Notify that the preview is about to be started and deliver preview size */ - onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height); - /* Now we can start a preview */ mCamera.startPreview(); }