问题描述
我正在尝试使用camera2 API录制视频,但是Camera的预览大小和视频与预期的不同。该对象在相机内预览中居中显示,但是在录制视频时,该对象会稍微移动。这些是2张图片,可以更好地说明我的意思
我正在使用以下代码 在打开相机的乐趣中
mVideoSize = chooseVideoSize(map.getOutputSizes(MediaRecorder::class.java),mCameraRecordingWidth!!,mCameraRecordingHeight!!)
mPreviewSize = chooseOptimalSize(map.getOutputSizes(SurfaceTexture::class.java),width,height,mVideoSize)
fun chooseVideoSize(choices: Array<Size>,configCameraWidth: Int,configCameraHeight: Int): Size {
for (size in choices) {
if (configCameraHeight == size.width && configCameraWidth == size.height) {
return size
}
}
for (size in choices) {
if (size.width == size.height * 4 / 3 && (size.width <= 1080 || size.width <= configCameraHeight)) {
return size
}
}
return choices[choices.size - 1]
}
private fun chooseOptimalSize(choices: Array<Size>,width: Int,height: Int,aspectRatio: Size?): Size {
val aspectRatioWidth = aspectRatio!!.width
val aspectRatioHeight = aspectRatio.height
val bigEnough: MutableList<Size> = ArrayList()
for (option in choices) {
if (option.height == option.width * aspectRatioHeight / aspectRatioWidth && option.width >= width && option.height >= height) {
bigEnough.add(option)
}
}
return if (bigEnough.size > 0) {
Collections.min(bigEnough,CompareSizesByArea())
} else {
choices[0]
}
}
我正在关注以下链接:https://github.com/googlearchive/android-Camera2Video 并使用AutoFitTextureView
override fun onMeasure(widthMeasureSpec: Int,heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec,heightMeasureSpec)
val width = MeasureSpec.getSize(widthMeasureSpec)
val height = MeasureSpec.getSize(heightMeasureSpec)
if (0 == mRatioWidth || 0 == mRatioHeight) {
setMeasuredDimension(width,height)
} else {
if (width < height * mRatioWidth / mRatioHeight) {
setMeasuredDimension(height * mRatioWidth / mRatioHeight,height)
} else {
setMeasuredDimension(width,width * mRatioHeight / mRatioWidth)
}
}
}
任何想法/解决方案对我来说都更为重要。非常感谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)