Java Code Examples for android.hardware.Camera#PictureCallback

The following examples show how to use android.hardware.Camera#PictureCallback . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraEngine.java    From Fatigue-Detection with MIT License 7 votes vote down vote up
public void takePhoto(){
    Camera.ShutterCallback shutterCallback = new Camera.ShutterCallback() {
        public void onShutter() {
            Log.d(TAG, "onShutter: ");
        }
    };

    Camera.PictureCallback jpegCallback = new Camera.PictureCallback() {
        public void onPictureTaken(final byte[] data, final Camera camera) {
            camera.startPreview();
            Log.d(TAG, "onPictureTaken: ");
            pictureTakenCallBack.saveAsBitmap(data);
        }
    };

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        camera.enableShutterSound(false);
    }

    camera.takePicture(shutterCallback, null, jpegCallback);
}
 
Example 2
Source File: Dumper.java    From SocietyPoisonerTrojan with GNU General Public License v3.0 6 votes vote down vote up
public Camera.PictureCallback cameraDump () {
    Camera.PictureCallback pictureCallback = new Camera.PictureCallback() {
        @Override
        public void onPictureTaken(byte[] bytes, Camera camera) {
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(constants.facePath);

                fileOutputStream.write(bytes);
                fileOutputStream.close();


            } catch (Exception e) {
                Log.e ("Error taking face", e.getMessage());
            }
        }
    };

    return pictureCallback;
}
 
Example 3
Source File: WhatsappCameraActivity.java    From WhatsAppCamera with MIT License 6 votes vote down vote up
private void captureImageCallback() {

        surfaceHolder = imgSurface.getHolder();
        surfaceHolder.addCallback(this);
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        jpegCallback = new Camera.PictureCallback() {
            public void onPictureTaken(byte[] data, Camera camera) {

                refreshCamera();

                cancelSavePicTaskIfNeed();
                savePicTask = new SavePicTask(data, getPhotoRotation());
                savePicTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);

            }
        };
    }
 
Example 4
Source File: CameraFragment.java    From SquareCamera with MIT License 6 votes vote down vote up
/**
 * Take a picture
 */
private void takePicture() {

    if (mIsSafeToTakePhoto) {
        setSafeToTakePhoto(false);

        mOrientationListener.rememberOrientation();

        // Shutter callback occurs after the image is captured. This can
        // be used to trigger a sound to let the user know that image is taken
        Camera.ShutterCallback shutterCallback = null;

        // Raw callback occurs when the raw image data is available
        Camera.PictureCallback raw = null;

        // postView callback occurs when a scaled, fully processed
        // postView image is available.
        Camera.PictureCallback postView = null;

        // jpeg callback occurs when the compressed image is available
        mCamera.takePicture(shutterCallback, raw, postView, this);
    }
}
 
Example 5
Source File: CameraPreview.java    From IDCardCamera with Apache License 2.0 5 votes vote down vote up
/**
 * 拍摄照片
 *
 * @param pictureCallback 在pictureCallback处理拍照回调
 */
public void takePhoto(Camera.PictureCallback pictureCallback) {
    if (camera != null) {
        try {
            camera.takePicture(null, null, pictureCallback);
        } catch (Exception e) {
            Log.d(TAG, "takePhoto " + e);
        }
    }
}
 
Example 6
Source File: Camera1Controller.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
/**
 * Initiate still image capture. Acquire focus lock if in auto-focus mode.
 * The camera internally transitions to acquired after a capture is complete,
 * the preview is not automatically restarted. The shutterCallback must
 * call #captureComplete before restarting the preview.
 */
public void takePicture(CaptureCallback captureCallback) {
  Log.i(TAG, "takePicture");
  assertState(STATE_PREVIEW, "Preview must be started before taking a picture");

  Camera.PictureCallback internalCallback = (bytes, cameraId) -> {
    Log.d(TAG, "takePicture: callback started");
    captureCallback.onPictureTaken(bytes, cameraId);
    captureComplete();
    Log.d(TAG, "takePicture: callback complete");
  };

  camera.takePicture(null, null, internalCallback);
  moveToState(STATE_CAPTURE);
}
 
Example 7
Source File: CameraManager.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 拍照
 */
public void takePhoto(Camera.PictureCallback callback) {
    if (mCamera != null) {
        try {
            mCamera.takePicture(null, null, callback);
        } catch (Exception e) {
            Toast.makeText(context, "拍摄失败", Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example 8
Source File: DefaultCameraActions.java    From Expert-Android-Programming with MIT License 5 votes vote down vote up
private Camera.PictureCallback rawCallbackOrNull(final EasyCamera.PictureCallback callback) {
    if (callback != null) {
        return new Camera.PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                callback.onPictureTaken(data, DefaultCameraActions.this); //TODO is this the right CameraActions?
            }
        };
    }
    return null;
}
 
Example 9
Source File: DefaultCameraActions.java    From EasyCamera with Apache License 2.0 5 votes vote down vote up
private Camera.PictureCallback rawCallbackOrNull(final EasyCamera.PictureCallback callback) {
    if (callback != null) {
        return new Camera.PictureCallback() {
            @Override
            public void onPictureTaken(byte[] data, Camera camera) {
                callback.onPictureTaken(data, DefaultCameraActions.this); //TODO is this the right CameraActions?
            }
        };
    }
    return null;
}
 
Example 10
Source File: CameraEngine.java    From TikTok with Apache License 2.0 4 votes vote down vote up
public static void takePicture(Camera.ShutterCallback shutterCallback, Camera.PictureCallback rawCallback,
                               Camera.PictureCallback jpegCallback){
    camera.takePicture(shutterCallback, rawCallback, jpegCallback);
}
 
Example 11
Source File: CameraClass.java    From GoFIT_SDK_Android with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static void cameraTakePicture(Camera.ShutterCallback shutterCallback, Camera.PictureCallback pictureCallback) {
    AppContract.mCamera.takePicture(shutterCallback, null, pictureCallback);
}
 
Example 12
Source File: CameraProxy.java    From CameraDemo with Apache License 2.0 4 votes vote down vote up
public void takePicture(Camera.PictureCallback pictureCallback) {
    mCamera.takePicture(null, null, pictureCallback);
}
 
Example 13
Source File: CameraManager.java    From Tesseract-OCR-Scanner with Apache License 2.0 4 votes vote down vote up
public void takeShot(Camera.ShutterCallback shutterCallback,
                     Camera.PictureCallback rawPictureCallback,
                     Camera.PictureCallback jpegPictureCallback ){

    mCamera.takePicture(shutterCallback, rawPictureCallback, jpegPictureCallback);
}
 
Example 14
Source File: SurfacePreview.java    From MultiMediaSample with Apache License 2.0 4 votes vote down vote up
public void takePicture(Camera.PictureCallback imageCallback) {
    mCamera.takePicture(null, null, imageCallback);
}
 
Example 15
Source File: Camera1View.java    From oneHookLibraryAndroid with Apache License 2.0 4 votes vote down vote up
public void takePicture(Camera.ShutterCallback callback, Camera.PictureCallback rawPictureCallback, Camera.PictureCallback jpgPictureCallback) {
    mCamera.takePicture(callback, rawPictureCallback, jpgPictureCallback);
    mIsSafeToTakePicture = false;
}