mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-01-01 10:07:18 +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
|
package com.simplemobiletools.camera.models
|
||||||
|
|
||||||
|
import android.annotation.TargetApi
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.os.Build
|
||||||
|
import android.util.Size
|
||||||
import com.simplemobiletools.camera.R
|
import com.simplemobiletools.camera.R
|
||||||
|
|
||||||
data class MySize(val width: Int, val height: Int) {
|
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"
|
isTwoToOne() -> "2:1"
|
||||||
else -> context.resources.getString(R.string.other)
|
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 {
|
} else {
|
||||||
configMap.getOutputSizes(SurfaceTexture::class.java)
|
configMap.getOutputSizes(SurfaceTexture::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
mPreviewSize = chooseOptimalPreviewSize(outputSizes, rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, currentResolution)
|
mPreviewSize = chooseOptimalPreviewSize(outputSizes, rotatedPreviewWidth, rotatedPreviewHeight, maxPreviewWidth, maxPreviewHeight, currentResolution)
|
||||||
|
|
||||||
mActivity.runOnUiThread {
|
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 bigEnough = ArrayList<Size>()
|
||||||
val notBigEnough = ArrayList<Size>()
|
val notBigEnough = ArrayList<Size>()
|
||||||
val width = aspectRatio.width
|
val width = selectedResolution.width
|
||||||
val height = aspectRatio.height
|
val height = selectedResolution.height
|
||||||
for (option in choices) {
|
for (option in choices) {
|
||||||
if (option.width <= maxWidth && option.height <= maxHeight && option.height == option.width * height / width) {
|
if (option.width <= maxWidth && option.height <= maxHeight && option.height == option.width * height / width) {
|
||||||
if (option.width >= textureViewWidth && option.height >= textureViewHeight) {
|
if (option.width >= textureViewWidth && option.height >= textureViewHeight) {
|
||||||
@ -406,7 +407,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
return when {
|
return when {
|
||||||
bigEnough.isNotEmpty() -> bigEnough.minBy { it.width * it.height }!!
|
bigEnough.isNotEmpty() -> bigEnough.minBy { it.width * it.height }!!
|
||||||
notBigEnough.isNotEmpty() -> notBigEnough.maxBy { 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