Example usage for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION

List of usage examples for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION

Introduction

In this page you can find the example usage for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION.

Prototype

Key JPEG_ORIENTATION

To view the source code for android.hardware.camera2 CaptureRequest JPEG_ORIENTATION.

Click Source Link

Document

The orientation for a JPEG image.

The clockwise rotation angle in degrees, relative to the orientation to the camera, that the JPEG picture needs to be rotated by, to be viewed upright.

Camera devices may either encode this value into the JPEG EXIF header, or rotate the image data to match this orientation.

Usage

From source file:fbla.hhs.eclat.Camera.Camera2BasicFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *//*from   w  w w .j  a v a 2 s  . c om*/
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            //Fragment frag;
            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                //showToast("Saved: " + mFile);
                Log.d(TAG, mFile.toString());
                //unlockFocus(session);
                switchFrag();
                /*ImagePreview fragment = new ImagePreview();
                fragment.setImage(mFile, frag);
                FragmentManager fragmentManager = getActivity().getFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                fragmentTransaction.replace(R.id.container, fragment);
                fragmentTransaction.addToBackStack(null);
                fragmentTransaction.commit();*/
                //onPause();
                /*ImageObtainedReaction imageReactor=new ImageObtainedReaction(mFile);
                imageReactor.run();*/
            }
        };
        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.vest.album.fragment.CameraBasicFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 */// ww w  .j a v  a2s  .  c om
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());
        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        captureBuilder.set(CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE,
                CaptureRequest.STATISTICS_LENS_SHADING_MAP_MODE_ON);
        captureBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, (long) ((214735991 - 13231) / 2));
        captureBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 0);
        captureBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, (10000 - 100) / 2);// ISO
        setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                //                    showToast("Saved: " + mFile);
                //                    Log.d(TAG, mFile.toString());
                //                    unlockFocus();
                handler.sendEmptyMessage(1);
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        callback.onPhotoError("?");
        e.printStackTrace();
    }
}

From source file:com.android.camera.one.v2.OneCameraZslImpl.java

/**
 * Request a single image.//from www. jav a  2s . co  m
 *
 * @return true if successful, false if there was an error submitting the
 *         capture request.
 */
private boolean sendSingleRequest(OneCamera.PhotoCaptureParameters params) {
    Log.v(TAG, "sendSingleRequest()");
    try {
        CaptureRequest.Builder builder;
        builder = mDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        builder.addTarget(mPreviewSurface);

        // Always add this surface for single image capture requests.
        builder.addTarget(mCaptureImageReader.getSurface());

        builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);

        Flash flashMode = Flash.OFF;
        addFlashToCaptureRequestBuilder(builder, flashMode);
        addRegionsToCaptureRequestBuilder(builder);

        builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
        builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE);

        // Tag this as a special request which should be saved.
        builder.setTag(RequestTag.EXPLICIT_CAPTURE);

        if (sCaptureImageFormat == ImageFormat.JPEG) {
            builder.set(CaptureRequest.JPEG_QUALITY, (byte) (JPEG_QUALITY));
            builder.set(CaptureRequest.JPEG_ORIENTATION,
                    CameraUtil.getJpegRotation(params.orientation, mCharacteristics));
        }

        mCaptureSession.capture(builder.build(), mCaptureManager, mCameraHandler);
        return true;
    } catch (CameraAccessException e) {
        Log.v(TAG, "Could not execute single still capture request.", e);
        return false;
    }
}

From source file:com.mygaadi.imageselectorlibrary.camera2.Camera2BasicFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *//*  ww  w. ja  va 2s  . co m*/
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                Log.d(TAG, mFile.toString());
                //file captured show preview

                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.android.littleblack.CameraFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *///from w w w  .  j  a  va2s. c o  m
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        // Eric Ju setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                showToast("Saved: " + mFile);
                Log.d(TAG, mFile.toString());
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:freed.cam.apis.camera2.modules.PictureModuleApi2.java

/**
 * PREVIEW STUFF/* w  ww  . j a va 2s  .  c o  m*/
 */

@Override
public void startPreview() {

    picSize = appSettingsManager.pictureSize.get();
    Log.d(TAG, "Start Preview");
    largestImageSize = Collections.max(Arrays.asList(cameraHolder.map.getOutputSizes(ImageFormat.JPEG)),
            new CompareSizesByArea());
    picFormat = appSettingsManager.pictureFormat.get();
    if (picFormat.equals("")) {
        picFormat = KEYS.JPEG;
        appSettingsManager.pictureFormat.set(KEYS.JPEG);
        parameterHandler.PictureFormat.onValueHasChanged(KEYS.JPEG);

    }

    if (picFormat.equals(KEYS.JPEG)) {
        String[] split = picSize.split("x");
        int width, height;
        if (split.length < 2) {
            mImageWidth = largestImageSize.getWidth();
            mImageHeight = largestImageSize.getHeight();
        } else {
            mImageWidth = Integer.parseInt(split[0]);
            mImageHeight = Integer.parseInt(split[1]);
        }
        //create new ImageReader with the size and format for the image
        Log.d(TAG, "ImageReader JPEG");
    } else if (picFormat.equals(CameraHolderApi2.RAW_SENSOR)) {
        Log.d(TAG, "ImageReader RAW_SENOSR");
        largestImageSize = Collections.max(
                Arrays.asList(cameraHolder.map.getOutputSizes(ImageFormat.RAW_SENSOR)),
                new CompareSizesByArea());
        mImageWidth = largestImageSize.getWidth();
        mImageHeight = largestImageSize.getHeight();
    } else if (picFormat.equals(CameraHolderApi2.RAW10)) {
        Log.d(TAG, "ImageReader RAW_SENOSR");
        largestImageSize = Collections.max(Arrays.asList(cameraHolder.map.getOutputSizes(ImageFormat.RAW10)),
                new CompareSizesByArea());
        mImageWidth = largestImageSize.getWidth();
        mImageHeight = largestImageSize.getHeight();
    }

    int sensorOrientation = cameraHolder.characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    int orientationToSet = (360 + cameraUiWrapper.getActivityInterface().getOrientation() + sensorOrientation)
            % 360;
    if (appSettingsManager.getApiString(AppSettingsManager.SETTING_OrientationHack).equals(KEYS.ON))
        orientationToSet = (360 + cameraUiWrapper.getActivityInterface().getOrientation() + sensorOrientation
                + 180) % 360;
    cameraHolder.SetParameter(CaptureRequest.JPEG_ORIENTATION, orientationToSet);

    // Here, we create a CameraCaptureSession for camera preview
    if (parameterHandler.Burst == null)
        SetBurst(1);
    else
        SetBurst(parameterHandler.Burst.GetValue());

}

From source file:com.example.aschere.cdhprototype2.Camera2RawFragment.java

/**
 * Send a capture request to the camera device that initiates a capture targeting the JPEG and
 * RAW outputs.//from w w w.  j a v a 2 s . c o  m
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void captureStillPictureLocked() {
    try {
        if (null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        captureBuilder.addTarget(mJpegImageReader.get().getSurface());
        captureBuilder.addTarget(mRawImageReader.get().getSurface());

        // Use the same AE and AF modes as the preview.
        setup3AControlsLocked(captureBuilder);

        // Set orientation.
        int rotation = Surface.ROTATION_0;
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, sensorToDeviceRotation(mCharacteristics, rotation));

        // Set request tag to easily track results in callbacks.
        captureBuilder.setTag(mRequestCounter.getAndIncrement());

        CaptureRequest request = captureBuilder.build();

        // Create an ImageSaverBuilder in which to collect results, and add it to the queue
        // of active requests.
        ImageSaver.ImageSaverBuilder jpegBuilder = new ImageSaver.ImageSaverBuilder(appContext)
                .setCharacteristics(mCharacteristics);
        ImageSaver.ImageSaverBuilder rawBuilder = new ImageSaver.ImageSaverBuilder(appContext)
                .setCharacteristics(mCharacteristics);

        mJpegResultQueue.put((int) request.getTag(), jpegBuilder);
        mRawResultQueue.put((int) request.getTag(), rawBuilder);

        mCaptureSession.capture(request, mCaptureCallback, mBackgroundHandler);

    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:research.dlsu.cacaoapp.Camera2BasicFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *//*  w  w w.ja v  a  2s .  co  m*/
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                showToast("Saved: " + mFile);
                Log.d(TAG, mFile.toString());
                // saveEntryToDatabase();

                // call match activity to save matched file
                Intent i = new Intent(getActivity(), MatchActivity27Jan.class);
                i.putExtra(ChoosePhotoActivity.EXTRA_PATH, mFile.getAbsolutePath());
                // cacaoImagePath = getIntent().getStringExtra(ChoosePhotoActivity.EXTRA_PATH);
                startActivityForResult(i, REQUEST_MATCH);

                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:org.tensorflow.demo.Camera2BasicFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *///from   w  w w. ja v  a  2s.com
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));
        sensorOrientation = rotation + getOrientation(rotation);
        frameToCropTransform = ImageUtils.getTransformationMatrix(previewWidth, previewHeight, INPUT_SIZE,
                INPUT_SIZE, sensorOrientation, MAINTAIN_ASPECT);

        cropToFrameTransform = new Matrix();
        frameToCropTransform.invert(cropToFrameTransform);
        classifier = TensorFlowImageClassifier.create(getActivity().getAssets(), MODEL_FILE, LABEL_FILE,
                INPUT_SIZE, IMAGE_MEAN, IMAGE_STD, INPUT_NAME, OUTPUT_NAME);

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                Log.d(TAG, mFile.toString());
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:research.dlsu.crabapp.Camera2BasicFragment.java

/**
 * Capture a still picture. This method should be called when we get a response in
 * {@link #mCaptureCallback} from both {@link #lockFocus()}.
 *///ww  w. ja v a 2  s  .  c o m
private void captureStillPicture() {
    try {
        final Activity activity = getActivity();
        if (null == activity || null == mCameraDevice) {
            return;
        }
        // This is the CaptureRequest.Builder that we use to take a picture.
        final CaptureRequest.Builder captureBuilder = mCameraDevice
                .createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureBuilder.addTarget(mImageReader.getSurface());

        // Use the same AE and AF modes as the preview.
        captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        setAutoFlash(captureBuilder);

        // Orientation
        int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
        captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation(rotation));

        CameraCaptureSession.CaptureCallback CaptureCallback = new CameraCaptureSession.CaptureCallback() {

            @Override
            public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                    @NonNull CaptureRequest request, @NonNull TotalCaptureResult result) {
                showToast("Saved: " + mFile);
                Log.d(TAG, mFile.toString());
                cu = saveEntryToDatabase();
                unlockFocus();
            }
        };

        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}