@SuppressLint("NewApi") @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); nv21 = new byte[PREVIEW_WIDTH * PREVIEW_HEIGHT * 2]; this.setPreviewCallback(new PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { synchronized (nv21) { System.arraycopy(data, 0, nv21, 0, data.length); isNV21ready = true; } } }); return view; }
public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); this.context=context; mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * software auto-focus. Only works for API level >=9. */ /* Camera.Parameters parameters = camera.getParameters(); for (String f : parameters.getSupportedFocusModes()) { if (f == Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
@SuppressWarnings("deprecation") public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * software auto-focus. Only works for API level >=9. */ //API9以上实现连续对焦 // Camera.Parameters parameters = camera.getParameters(); // for (String f : parameters.getSupportedFocusModes()) { // if (f == Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { // parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); // autoFocusCallback = null; // break; // } // } // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
@Override public void run() { if (!Running || mCamera == null) { // handled by shutDown() this.cancel(); return; } mCamera.setOneShotPreviewCallback(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera camera) { // currentPreview = data; long t = System.currentTimeMillis(); imageQueue.add(new TimeValue(t, jpegFromPreview(data))); // convert to jpeg on the fly, spread out the CPU work // imageQueue.add(new TimeValue(t, data)); if (debug) Log.i(TAG, "CameraTask, time: " + t); } }); }
public void surfaceCreated(SurfaceHolder holder) { // The Surface has been created, acquire the camera and tell it where // to draw. camera = Camera.open(); try { camera.setPreviewDisplay(holder); camera.setPreviewCallback(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera arg1) { Preview.this.invalidate(); } }); } catch (IOException e) { e.printStackTrace(); } }
public BarcodePreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; Camera.Parameters parameters = camera.getParameters(); for (String f : parameters.getSupportedFocusModes()) { if (f == Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } mHolder = getHolder(); mHolder.addCallback(this); }
private PreviewCallback createPreviewCallback() { PreviewCallback previewCallback = new Camera.PreviewCallback() { public void onPreviewFrame(byte[] data, Camera camera) { Camera.Parameters parameters = camera.getParameters(); Camera.Size size = parameters.getPreviewSize(); Image barcode = new Image(size.width, size.height, "NV21"); barcode.setData(data); barcode = barcode.convert("Y800"); int result = mScanner.scanImage(barcode); if (result != 0) { mPreviewing = false; releaseCamera(); SymbolSet syms = mScanner.getResults(); for (Symbol sym : syms) { Flow.with(ScanQRConfigActivity.this).scanned(sym); break; } } } }; return previewCallback; }
public XCameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; mPreviewCallback = previewCb; mAutoFocusCallback = autoFocusCb; // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
public void surfaceCreated(SurfaceHolder holder) { Log.i(TAG, "surfaceCreated"); mCamera = Camera.open(); mCamera.setPreviewCallbackWithBuffer(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera camera) { synchronized (SampleViewBase.this) { System.arraycopy(data, 0, mFrame, 0, data.length); SampleViewBase.this.notify(); } camera.addCallbackBuffer(mBuffer); } }); (new Thread(this)).start(); }
public void requestPreviewFrame(final PreviewCallback callback) { try { camera.setOneShotPreviewCallback(callback); } catch (final RuntimeException x) { log.warn("problem requesting preview frame, callback won't be called", x); } }
@Override public void run() { cameraManager.requestPreviewFrame(new PreviewCallback() { @Override public void onPreviewFrame(final byte[] data, final Camera camera) { decode(data); } }); }
@SuppressWarnings("deprecation") public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use software * auto-focus. Only works for API level >=9. */ Camera.Parameters parameters = camera.getParameters(); for (String f: parameters.getSupportedFocusModes()) { if (f == Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * software auto-focus. Only works for API level >=9. */ /* Camera.Parameters parameters = camera.getParameters(); for (String f : parameters.getSupportedFocusModes()) { if (f == Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
@Override public void setPreviewCallback(PreviewCallback my) { Log.e("test++++++++++++++", "setPreviewCallback"); if (cameras != null) { cameras.setPreviewCallback(my); } }
public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; // Install a SurfaceHolder.Callback so we get notified when // the underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); }
CameraPreview(Context context, PreviewCallback previewCallback, AutoFocusCallback autoFocusCb) { super(context); mPreviewCallback = previewCallback; mAutoFocusCallback = autoFocusCb; mSurfaceView = new SurfaceView(context); addView(mSurfaceView); // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = mSurfaceView.getHolder(); mHolder.addCallback(this); mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
@Override public void run() { if (fromGallery) { cameraHandler.postDelayed(fetchAndDecodeRunnable, 500); return; } cameraManager.requestPreviewFrame(new PreviewCallback() { @Override public void onPreviewFrame(final byte[] data, final Camera camera) { decode(data); } }); }
public void setPreviewCallbackWithBuffer(Camera camera, PreviewCallback cb) { try { if (mMethodSetPreviewCallbackWithBuffer != null) { Object[] argList = new Object[1]; argList[0] = cb; mMethodSetPreviewCallbackWithBuffer.invoke(camera, argList); } } catch (Exception e) { Log.w(LOG_TAG, "CameraHideMethods:mMethodSetPreviewCallbackWithBuffer()", e); } }
@SuppressWarnings("deprecation") public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use software * auto-focus. Only works for API level >=9. */ /* * Camera.Parameters parameters = camera.getParameters(); for (String f * : parameters.getSupportedFocusModes()) { if (f == * Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { * mCamera.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); * autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
public CameraPreview(Context context, Camera camera, PreviewCallback previewCb, AutoFocusCallback autoFocusCb) { super(context); mCamera = camera; previewCallback = previewCb; autoFocusCallback = autoFocusCb; /* * Set camera to continuous focus if supported, otherwise use * software auto-focus. Only works for API level >=9. */ /* Camera.Parameters parameters = camera.getParameters(); for (String f : parameters.getSupportedFocusModes()) { if (f == Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) { mCamera.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE); autoFocusCallback = null; break; } } */ // Install a SurfaceHolder.Callback so we get notified when the // underlying surface is created and destroyed. mHolder = getHolder(); mHolder.addCallback(this); // deprecated setting, but required on Android versions prior to 3.0 //mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); }
public void run() { cameraManager.requestPreviewFrame(new PreviewCallback() { public void onPreviewFrame(final byte[] data, final Camera camera) { decode(data); } }); }
public void setCamera(Camera camera, PreviewCallback previewCallback) { this.mCamera = camera; this.mPreviewCallback = previewCallback; this.mAutoFocusHandler = new Handler(); }
public void requestPreviewFrame(final PreviewCallback callback) { camera.setOneShotPreviewCallback(callback); }
public void setPreviewCallback(PreviewCallback previewCallback) { if (this.mCamera != null){ mCamera.setPreviewCallback(previewCallback); } }
public void setOneShotPreviewCallback(PreviewCallback callback) { if (null == mCamera) { return; } mCamera.setOneShotPreviewCallback(callback); }
public void setPreviewCallback(PreviewCallback callback) { if (null == mCamera) { return; } mCamera.setPreviewCallback(callback); }
private void takePictureWithoutShutterSound() { if (mCamera != null) { mCamera.setOneShotPreviewCallback(new PreviewCallback() { public void onPreviewFrame(byte[] data, Camera camera) { // Stop preview so that end-user can notice that we are taking a picture. mCamera.stopPreview(); // Allocate bitmap data. Size previewSize = mCamera.getParameters().getPreviewSize(); final int width = previewSize.width; final int height = previewSize.height; int[] rgb = new int[(width * height)]; // Convert from data(YUV420) to rgb(RGB). ImageUtil.decodeYUV420SP(rgb, data, width, height); // Create bitmap to be converted to JPG. Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bmp.setPixels(rgb, 0, width, 0, 0, width, height); // Directory. File dirFile = new File(CameraUtil.DIR_SAVE_PICS); if (!dirFile.exists()) { dirFile.mkdirs(); } // Date to be used for JPG filename. String filepath = CameraUtil.createPictureFilePath(); ImageUtil.saveBitmapAsFile(filepath, bmp, Bitmap.CompressFormat.JPEG); // Add EXIF data. try { ExifInterface ei = new ExifInterface(filepath); ei.setAttribute(ExifInterface.TAG_ORIENTATION, mCameraUtil.displayRotationToExifOrientation(getDisplayRotation()) + ""); ei.saveAttributes(); } catch (IOException e) { e.printStackTrace(); } // Request MediaScanner to scan the file to be saved right now, and to add it to the media DB. ImageUtil.scanFile(getApplicationContext(), filepath); // Inform end-user that picture has been saved. Toast.makeText(getApplicationContext(), getString(R.string.toast_picture_saved), Toast.LENGTH_SHORT).show(); // Restart preview. startPreview(); } }); } else { Log.w(LOG_TAG, "takePictureWithoutShutterSound(), mCamera: null"); } }