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

Non-default aspect ratio will be ignored w/ Camera2 #46

Closed
foooorsyth opened this issue Nov 10, 2016 · 1 comment
Closed

Non-default aspect ratio will be ignored w/ Camera2 #46

foooorsyth opened this issue Nov 10, 2016 · 1 comment

Comments

@foooorsyth
Copy link

foooorsyth commented Nov 10, 2016

In Camera2.setAspectRatio(AspectRatio ratio), you have this check at the start of the method:

if (ratio == null || ratio.equals(mAspectRatio) ||
                **!mPreviewSizes.ratios().contains(ratio)**) {
            // TODO: Better error handling
            return;
}

setAspectRatio() is called in the constructor of CameraView once the custom XML attribute value for app:aspectRatio is retrieved. At this time mPreviewSizes.ratios() will always be empty because camera info has not been collected yet, which happens on Camera2.start(). So, this method will always return without doing anything, and the default aspect ratio -- 4:3 -- will always be used.

I fixed this by collecting camera info before this check

chooseCameraIdByFacing();
collectCameraInfo();
if (ratio == null || ratio.equals(mAspectRatio) ||
                !mPreviewSizes.ratios().contains(ratio)) {
            // TODO: Better error handling
            return;
}
@yaraki yaraki closed this as completed in 9bbe07b Apr 21, 2017
@gregkorossy
Copy link

This bug is still present...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants