美文网首页
获取 byte[] 数据显示在 surfaceview 上

获取 byte[] 数据显示在 surfaceview 上

作者: 白银之火 | 来源:发表于2020-11-16 17:03 被阅读0次
        private var mCanvas: Canvas? = null
        val videoBitmap: Bitmap = Bitmap.createBitmap(800, 600, Bitmap.Config.ARGB_8888)
    
        fun initVideo() {
            GlobalScope.launch {
                delay(1000)
                mainViewModel.requestImage(ComputerStrict.OnRecieveImageListener { data ->
                    mCanvas= mBinding.sfv.holder.lockCanvas()
                    mCanvas!!.drawColor(Color.BLACK)
                    val buffer = ByteBuffer.wrap(data)
                    videoBitmap.copyPixelsFromBuffer(buffer)
    
                    // 计算宽高缩放率,用宽填充满
                    val matrix = Matrix()
                    val scaleWidth = mBinding.sfv.width.toFloat() / 800
    //            val scaleHeight = mBinding.sfv.height.toFloat() / 600
                    matrix.postScale(scaleWidth, scaleWidth)
                    mCanvas!!.drawBitmap(videoBitmap, matrix, null)
                    if (mCanvas!= null) {
                        mBinding.sfv.holder.unlockCanvasAndPost(m_canvas)
                    }
                })
            }
        }
    

    相关文章

      网友评论

          本文标题:获取 byte[] 数据显示在 surfaceview 上

          本文链接:https://www.haomeiwen.com/subject/fodzbktx.html