美文网首页
2023-02-23 关于Matrix 对TextureView

2023-02-23 关于Matrix 对TextureView

作者: 谦谦行者 | 来源:发表于2023-02-22 16:14 被阅读0次

    1 创建一个Matrix
    2 通过preScale()方法设置缩放比例与中心点
    3 TextureView.setTransform(Matrix )
    4 TextureView.postInvalidate() 刷新

    // 放大的点击事件
    fun zoomIn(){
      // 播放视频的view
      val textureView = findViewById(R.id.TextureView)
      val matrix = Matrix()
      // 为了重复点击能在之前基础上放大
      textureView.getTransform(matrix)
    
      // sx/sy  -1~1 代表缩小  >1或<-1 代表放大
      // 其中,负值还代表根据中心轴翻转
      // 第一、第二个参数,代表放大还是缩小,sx/sy
      // 第三、第四个参数,代表缩放的原点,下面是以中心点缩放
      // postScale()和preScale() 效果相同,不知道有什么区别
      matrix.postScale(2f,2f,(binding.surfaceView.width/2).toFloat(),(binding.surfaceView.height/2).toFloat())
      // 设置矩阵
      textureView.setTransform(matrix)
      // 刷新view
      textureView.postInvalidate()
    }
    
    // 缩小的点击事件
    fun zoomOut(){
      // 播放视频的view
      val textureView = findViewById(R.id.TextureView)
      val matrix = Matrix()
      // 为了重复点击能在之前基础上放大
      textureView.getTransform(matrix)
    
      // 0.5 代表画面缩小回之前的一半,对应上面放大2倍的操作
      matrix.postScale(0.5f,0.5f,(binding.surfaceView.width/2).toFloat(),(binding.surfaceView.height/2).toFloat())
      // 设置矩阵
      textureView.setTransform(matrix)
      // 刷新view
      textureView.postInvalidate()
    }
    

    相关文章

      网友评论

          本文标题:2023-02-23 关于Matrix 对TextureView

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