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