Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Add a getter to get the camera orientation relative to the devices native orientation #269

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ public void onPictureTaken(byte[] data, Camera camera) {
}
}

@Override
int getCameraOrientation() {
return mCameraInfo.orientation;
}

@Override
void setDisplayOrientation(int displayOrientation) {
if (mDisplayOrientation == displayOrientation) {
Expand Down
13 changes: 11 additions & 2 deletions library/src/main/api21/com/google/android/cameraview/Camera2.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ public void onImageAvailable(ImageReader reader) {
private boolean mAutoFocus;

private int mFlash;

private int mCameraOrientation;

private int mDisplayOrientation;

Expand Down Expand Up @@ -341,6 +343,11 @@ void takePicture() {
}
}

@Override
int getCameraOrientation() {
return mCameraOrientation;
}

@Override
void setDisplayOrientation(int displayOrientation) {
mDisplayOrientation = displayOrientation;
Expand Down Expand Up @@ -407,8 +414,8 @@ private boolean chooseCameraIdByFacing() {

/**
* <p>Collects some information from {@link #mCameraCharacteristics}.</p>
* <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes}, and optionally,
* {@link #mAspectRatio}.</p>
* <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes},
* {@link #mCameraOrientation}, and optionally, {@link #mAspectRatio}.</p>
*/
private void collectCameraInfo() {
StreamConfigurationMap map = mCameraCharacteristics.get(
Expand All @@ -435,6 +442,8 @@ private void collectCameraInfo() {
if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
mAspectRatio = mPreviewSizes.ratios().iterator().next();
}

mCameraOrientation = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
}

protected void collectPictureSizes(SizeMap sizes, StreamConfigurationMap map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ View getView() {

abstract void takePicture();

abstract int getCameraOrientation();

abstract void setDisplayOrientation(int displayOrientation);

interface Callback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ public int getFlash() {
return mImpl.getFlash();
}

/**
* Gets the camera orientation relative to the devices native orientation.
*
* @return The orientation of the camera.
*/
public int getCameraOrientation() {
return mImpl.getCameraOrientation();
}

/**
* Take a picture. The result will be returned to
* {@link Callback#onPictureTaken(CameraView, byte[])}.
Expand Down