问题描述
我想从相机以RGB_565格式获取数据(预览期间),并想以相同格式在SurfaceView上显示它。这是我为此编写的代码:
class CameraPreview(
context: Context,private val mCamera: Camera) : SurfaceView(context),SurfaceHolder.Callback,Camera.PreviewCallback {
private val mHolder: SurfaceHolder = holder.apply {
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
**setFormat(PixelFormat.RGB_565)**
addCallback(this@CameraPreview)
// deprecated setting,but required on Android versions prior to 3.0
setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS)
}
override fun surfaceCreated(holder: SurfaceHolder) {
var cameraParameters: Camera.Parameters? = mCamera.parameters
cameraParameters?.set("orientation","portrait")
mCamera.setdisplayOrientation(90)
cameraParameters?.setRotation(90)
**cameraParameters?.previewFormat=ImageFormat.RGB_565**
var x=cameraParameters?.previewFormat
mCamera.parameters = cameraParameters
// The Surface has been created,Now tell the camera where to draw the preview.
mCamera.apply {
try {
setPreviewdisplay(holder)
setPreviewCallback(this@CameraPreview)
startPreview()
} catch (e: IOException) {
Log.d(TAG,"Error setting camera preview: ${e.message}")
}
}
}
//Surface Changed
//Surface Destroyed
//OnPreviewCallback
}
但是当我运行代码时,表面视图显示白色屏幕。请注意,我已将重要行突出显示为** ..... **。删除这些“重要”线后,表面视图将正确显示摄像机的输出(默认情况下它接受NV21格式)。我必须对代码进行哪些更改,以使“曲面”视图接受并以RGB_565格式显示图像?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)