Java 类android.hardware.Camera.PreviewCallback 实例源码

项目:Fatigue-Detection    文件:FaceOverlapFragment.java   
@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;
}
项目:PaoMovie    文件:CameraPreview.java   
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);
}
项目:QRDataTransfer-Android    文件:CameraPreview.java   
@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);
    }
项目:cloudturbine    文件:CTandroidAV.java   
@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);
                    }
                });
            }
项目:androtelebot    文件:Preview.java   
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();
    }
}
项目:KendaliPintuAndroid    文件:BarcodePreview.java   
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);
}
项目:glass-warehouse-automation    文件:ScanQRConfigActivity.java   
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;
}
项目:openxface-android    文件:XCameraPreview.java   
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);
}
项目:higgs-bot    文件:SampleViewBase.java   
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();
}
项目:okwallet    文件:CameraManager.java   
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);
    }
}
项目:okwallet    文件:ScanActivity.java   
@Override
public void run() {
    cameraManager.requestPreviewFrame(new PreviewCallback() {
        @Override
        public void onPreviewFrame(final byte[] data, final Camera camera) {
            decode(data);
        }
    });
}
项目:lbry-android    文件:ScanActivity.java   
@Override
public void run()
{
    cameraManager.requestPreviewFrame(new PreviewCallback()
    {
        @Override
        public void onPreviewFrame(final byte[] data, final Camera camera)
        {
            decode(data);
        }
    });
}
项目:ZbarCode    文件:CameraPreview.java   
@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);
  }
项目:AndroidQrCodeScanner    文件:CameraPreview.java   
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);
}
项目:ombuds-android    文件:ScanActivity.java   
@Override
public void run()
{
    cameraManager.requestPreviewFrame(new PreviewCallback()
    {
        @Override
        public void onPreviewFrame(final byte[] data, final Camera camera)
        {
            decode(data);
        }
    });
}
项目:WiCamera3D    文件:VideoSurfaceView2D.java   
@Override
public void setPreviewCallback(PreviewCallback my) {
    Log.e("test++++++++++++++", "setPreviewCallback");
    if (cameras != null) {
        cameras.setPreviewCallback(my);

    }
}
项目:WiCamera3D    文件:VideoSurfaceView.java   
@Override
public void setPreviewCallback(PreviewCallback my) {
    Log.e("test++++++++++++++", "setPreviewCallback");
    if (cameras != null) {
        cameras.setPreviewCallback(my);

    }
}
项目:batatas-android    文件:CameraPreview.java   
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);
}
项目:V-Scan    文件:CameraPreview.java   
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);
}
项目:virtour    文件:CameraPreview.java   
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);
}
项目:My-Wallet-Android    文件:CameraPreview.java   
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);
}
项目:bither-android    文件:ScanActivity.java   
@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);
        }
    });
}
项目:camera-through-wallpaper    文件:CameraHideMethods.java   
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);
    }
}
项目:QRCodeTest    文件:CameraPreview.java   
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);
}
项目:templecoin-android-wallet    文件:ScanActivity.java   
@Override
public void run()
{
    cameraManager.requestPreviewFrame(new PreviewCallback()
    {
        @Override
        public void onPreviewFrame(final byte[] data, final Camera camera)
        {
            decode(data);
        }
    });
}
项目:ZBarScanProj    文件:CameraPreview.java   
@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);
}
项目:FAVShop    文件:CameraPreview.java   
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);
}
项目:GlassWifiConnect    文件:CameraPreview.java   
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);
}
项目:QR-auth-android    文件:CameraPreview.java   
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);
}
项目:goldcoin-android    文件:ScanActivity.java   
public void run()
{
    cameraManager.requestPreviewFrame(new PreviewCallback()
    {
        public void onPreviewFrame(final byte[] data, final Camera camera)
        {
            decode(data);
        }
    });
}
项目:boohee_v5.6    文件:CameraPreview.java   
public void setCamera(Camera camera, PreviewCallback previewCallback) {
    this.mCamera = camera;
    this.mPreviewCallback = previewCallback;
    this.mAutoFocusHandler = new Handler();
}
项目:lbry-android    文件:CameraManager.java   
public void requestPreviewFrame(final PreviewCallback callback)
{
    camera.setOneShotPreviewCallback(callback);
}
项目:faceswap    文件:CameraPreview.java   
public void setPreviewCallback(PreviewCallback previewCallback) {
    if (this.mCamera != null){
        mCamera.setPreviewCallback(previewCallback);
    }
}
项目:ombuds-android    文件:CameraManager.java   
public void requestPreviewFrame(final PreviewCallback callback)
{
    camera.setOneShotPreviewCallback(callback);
}
项目:DroidLGTM    文件:CameraPreview.java   
public void setOneShotPreviewCallback(PreviewCallback callback) {
    if (null == mCamera) {
        return;
    }
    mCamera.setOneShotPreviewCallback(callback);
}
项目:DroidLGTM    文件:CameraPreview.java   
public void setPreviewCallback(PreviewCallback callback) {
    if (null == mCamera) {
        return;
    }
    mCamera.setPreviewCallback(callback);
}
项目:gabriel    文件:CameraPreview.java   
public void setPreviewCallback(PreviewCallback previewCallback) {
    if (this.mCamera != null){
        mCamera.setPreviewCallback(previewCallback);
    }
}
项目:gabriel    文件:CameraPreview.java   
public void setPreviewCallback(PreviewCallback previewCallback) {
    if (this.mCamera != null){
        mCamera.setPreviewCallback(previewCallback);
    }
}
项目:bither-android    文件:CameraManager.java   
public void requestPreviewFrame(final PreviewCallback callback) {
    camera.setOneShotPreviewCallback(callback);
}
项目:camera-through-wallpaper    文件:WalkAroundWallpaper.java   
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");
    }
}