Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to capture images in 16:9 #116

Closed
pcm2a opened this issue Jan 17, 2019 · 8 comments
Closed

How to capture images in 16:9 #116

pcm2a opened this issue Jan 17, 2019 · 8 comments

Comments

@pcm2a
Copy link
Contributor

pcm2a commented Jan 17, 2019

Can you point me in the right direction on how to set the aspect ratio for capturing an image with Camera2? The equivalent of setPictureSize on Camera1. I would like to do something similar to what we did with videos and allow taking photos in 4:3 or 16:9. Currently with a full screen preview the captured image is 4:3.

@pcm2a
Copy link
Contributor Author

pcm2a commented Jan 17, 2019

I figured this out and will update it to be similar to videos, allowing for Max 4:3 or Max 16:9.

val largestPicture = pictureSizes.sizes(AspectRatio.Ratio16x9).last()

@pcm2a pcm2a closed this as completed Jan 17, 2019
@pcm2a
Copy link
Contributor Author

pcm2a commented Jan 17, 2019

I finally figured it out, no code changes needed. The below setting, put in the camera opened listener seems to do the trick.

camera.addCameraOpenedListener {
   camera.aspectRatio = AspectRatio.Ratio16x9
 }

@pvasa
Copy link
Owner

pvasa commented Jan 18, 2019

Not necessarily from opened listener. It can be set once the view is created using

camera.aspectRatio = AspectRatio.of(4, 3) // any valid aspect ratio

Also all supported aspect ratios can be found in camera.supportedAspectRatios

@pcm2a
Copy link
Contributor Author

pcm2a commented Jan 18, 2019

I'll give that a shot also and report back. I tried setting app:aspectRatio="16:9" in the layout file but that seemed to give an error, maybe only works from the class file. Thanks for all the active development you are putting in to this project!

@pcm2a pcm2a reopened this Jan 21, 2019
@pcm2a
Copy link
Contributor Author

pcm2a commented Jan 21, 2019

Reopening to make sure I understand how 16:9 photos are supposed to be captured. The only way that seems to work good is in the opened listener.

@pvasa
Copy link
Owner

pvasa commented Jan 24, 2019

@pcm2a just found out one of the changes made recently broke this functionality. In CameraView.kt. Changing config.aspectRatio.observeForever {..} to config.aspectRatio.observe(camera) {..} will fix it.

This change will make sure aspectRatio value specified in xml is only emitted and processed once camera is correctly initialized to a point where it can validate the aspectRatio and set preview based on it. I will push a fix right now.

@pvasa
Copy link
Owner

pvasa commented Jan 24, 2019

With #134, one can specify the aspect ratio in xml directly like app:aspectRatio="16:9" and the camera preview will be initialized in that aspect ratio. Even the pictures will be taken in that aspect ratio.

@pcm2a
Copy link
Contributor Author

pcm2a commented Jan 30, 2019

Setting 16:9 in the xml is now working.

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

No branches or pull requests

2 participants