mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2024-12-29 08:40:16 +01:00
use the selected resolution as preview, if nothing better is found
This commit is contained in:
parent
cf64374411
commit
63d228a50e
@ -1,6 +1,9 @@
|
||||
package com.simplemobiletools.camera.models
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.util.Size
|
||||
import com.simplemobiletools.camera.R
|
||||
|
||||
data class MySize(val width: Int, val height: Int) {
|
||||
@ -41,4 +44,7 @@ data class MySize(val width: Int, val height: Int) {
|
||||
isTwoToOne() -> "2:1"
|
||||
else -> context.resources.getString(R.string.other)
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
fun toSize() = Size(width, height)
|
||||
}
|
||||
|
@ -369,6 +369,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||
} else {
|
||||
configMap.getOutputSizes(SurfaceTexture::class.java)
|
||||
}
|
||||
|
||||
mPreviewSize = chooseOptimalPreviewSize(outputSizes, rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, currentResolution)
|
||||
|
||||
mActivity.runOnUiThread {
|
||||
@ -388,11 +389,11 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||
}
|
||||
}
|
||||
|
||||
private fun chooseOptimalPreviewSize(choices: Array<Size>, textureViewWidth: Int, textureViewHeight: Int, maxWidth: Int, maxHeight: Int, aspectRatio: MySize): Size {
|
||||
private fun chooseOptimalPreviewSize(choices: Array<Size>, textureViewWidth: Int, textureViewHeight: Int, maxWidth: Int, maxHeight: Int, selectedResolution: MySize): Size {
|
||||
val bigEnough = ArrayList<Size>()
|
||||
val notBigEnough = ArrayList<Size>()
|
||||
val width = aspectRatio.width
|
||||
val height = aspectRatio.height
|
||||
val width = selectedResolution.width
|
||||
val height = selectedResolution.height
|
||||
for (option in choices) {
|
||||
if (option.width <= maxWidth && option.height <= maxHeight && option.height == option.width * height / width) {
|
||||
if (option.width >= textureViewWidth && option.height >= textureViewHeight) {
|
||||
@ -406,7 +407,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||
return when {
|
||||
bigEnough.isNotEmpty() -> bigEnough.minBy { it.width * it.height }!!
|
||||
notBigEnough.isNotEmpty() -> notBigEnough.maxBy { it.width * it.height }!!
|
||||
else -> choices.first()
|
||||
else -> selectedResolution.toSize()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user