RedApparat / Fotoapparat

Making Camera for Android more friendly. 📸
Apache License 2.0
3.81k stars 405 forks source link

Custom aspect ratio is not working #303

Closed nominalista closed 5 years ago

nominalista commented 5 years ago

I wanted to set the aspect ratio for the preview and picture the same as screen aspect ratio.

val displayMetrics = DisplayMetrics()
activity.windowManager.defaultDisplay.getMetrics(displayMetrics)
val screenAspectRatio = displayMetrics.heightPixels.toFloat() / displayMetrics.widthPixels.toFloat()

val cameraConfiguration = CameraConfiguration(
        pictureResolution = aspectRatio(screenAspectRation, highestResolution()),
        previewResolution = aspectRatio(screenAspectRation, highestResolution()))

Unfortunately as the result I get black screen (despite the fact that screenAspectRatio is correct value). 4:3 and 16:9 ratios are working correctly.

dmitry-zaitsev commented 5 years ago

What happens is that Fotoapparat tries to select a size with an aspect ratio which is exactly equal to screenAspectRatio (you have a typo btw). It is very unlikely that there is a size with exactly matching ratio so nothing is selected and you see a black screen.

aspectRatio() has an optional 3rd parameter which defines a tolerance of how far the actual aspect ratio might be from what you defined.

nominalista commented 5 years ago

Thanks, I assumed that Fotoapparat can choose any aspect ratio.