List of usage examples for android.hardware Camera setPreviewCallbackWithBuffer
public final void setPreviewCallbackWithBuffer(PreviewCallback cb)
Installs a callback to be invoked for every preview frame, using buffers supplied with #addCallbackBuffer(byte[]) , in addition to displaying them on the screen.
From source file:uk.ac.horizon.artcodes.camera.CameraView.java
public void setDetector(Detector processor, Experience experience) { this.experience = experience; this.detector = processor; if (detector != null) { if (camera == null) { createCamera();//w w w . j a va 2 s.c o m } if (camera != null) { cameraIsFocused = !deviceNeedsTapToFocus; camera.addCallbackBuffer(detector.createBuffer(info, surfaceWidth, surfaceHeight)); camera.setPreviewCallbackWithBuffer(new Camera.PreviewCallback() { @Override public void onPreviewFrame(final byte[] data, final Camera camera) { boolean focusedOnThisFrame = false; if (deviceNeedsTapToFocus || !cameraIsFocused) { synchronized (cameraFocusLock) { while (!cameraIsFocused) { try { Log.i("FOCUS", "cameraFocusLock.wait(); Thread: " + Thread.currentThread().getName()); focusedOnThisFrame = true; cameraFocusLock.wait(); } catch (InterruptedException ignored) { } } Log.i("FOCUS", "notified Thread: " + Thread.currentThread().getName()); } } if (cameraIsFocused) { Log.i("FOCUS", "cameraIsFocused test: " + cameraIsFocused); if (!focusedOnThisFrame) { detector.setData(data); } camera.addCallbackBuffer(data); } } }); } if (Camera.getNumberOfCameras() > 1) { detector.getSettings().add(new DetectorSetting() { @Override public void nextValue() { stopCamera(); facing = 1 - facing; startCamera(); } @Override public int getIcon() { switch (facing) { case Camera.CameraInfo.CAMERA_FACING_BACK: return R.drawable.ic_camera_rear_24dp; case Camera.CameraInfo.CAMERA_FACING_FRONT: return R.drawable.ic_camera_front_24dp; } return 0; } @Override public int getText() { switch (facing) { case Camera.CameraInfo.CAMERA_FACING_BACK: return R.string.camera_rear; case Camera.CameraInfo.CAMERA_FACING_FRONT: return R.string.camera_front; } return 0; } }); } } }
From source file:com.nekomeshi312.whiteboardcorrection.CameraViewFragment.java
public void stopPreview() { // TODO Auto-generated method stub Log.i(LOG_TAG, "stopPreview"); if (mCameraSetting == null) return;/*from w ww .j a v a2 s . com*/ try { if (mCameraSetting.getCamera() != null) { final Camera camera = mCameraSetting.getCamera(); camera.setPreviewCallbackWithBuffer(null); mBuffer = null; camera.stopPreview(); if (mWbDetect != null) { mWbDetect = null; } if (mLineDetector != null) { mLineDetector.cleanUp(); mLineDetector = null; } if (mMatYuv != null) { mMatYuv.release(); mMatYuv = null; } if (mMatRgba != null) { mMatRgba.release(); mMatRgba = null; } if (mBmp != null) { mBmp.recycle(); mBmp = null; } } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.nekomeshi312.whiteboardcorrection.CameraViewFragment.java
private void setPreviewCallback() { if (!mCameraSetting.isCameraOpen()) return;/* ww w . ja v a 2 s .com*/ final Camera camera = mCameraSetting.getCamera(); //?? bit/pixel PixelFormat pixelinfo = new PixelFormat(); int pixelformat = camera.getParameters().getPreviewFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); //??? Camera.Parameters parameters = camera.getParameters(); Size sz = parameters.getPreviewSize(); //?????? int bufSize = sz.width * sz.height * pixelinfo.bitsPerPixel / 8; mBuffer = new byte[bufSize]; camera.addCallbackBuffer(mBuffer); camera.setPreviewCallbackWithBuffer(this); }