如何让一个特殊的SurfaceView只绘制部分区域?

zero15 2015-09-14 12:12:01
这个SurfaceView是被用来显示摄像头的Preview的,不知道有什么办法可以裁剪这个SurfaceView
...全文
452 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Birds2018 2015-09-14
  • 打赏
  • 举报
回复
用GLSurfaceView Render,回调函数里面用OpenGL 去处理 想怎么处理都能弄。
zero15 2015-09-14
  • 打赏
  • 举报
回复
引用 2 楼 x13945 的回复:
[quote=引用 1 楼 x13945 的回复:] matrix

    /**
     * <p>Sets the transform to associate with this texture view.
     * The specified transform applies to the underlying surface
     * texture and does not affect the size or position of the view
     * itself, only of its content.</p>
     * 
     * <p>Some transforms might prevent the content from drawing
     * all the pixels contained within this view's bounds. In such
     * situations, make sure this texture view is not marked opaque.</p>
     * 
     * @param transform The transform to apply to the content of
     *        this view.
     * 
     * @see #getTransform(android.graphics.Matrix) 
     * @see #isOpaque() 
     * @see #setOpaque(boolean) 
     */
    public void setTransform(Matrix transform) {
        mMatrix.set(transform);
        mMatrixChanged = true;
        invalidateParentIfNeeded();
    }
[/quote] 有办法在摄像头把预览图渲染到surfaceView上之前把数据改掉么。。。
zero15 2015-09-14
  • 打赏
  • 举报
回复
引用 2 楼 x13945 的回复:
[quote=引用 1 楼 x13945 的回复:] matrix

    /**
     * <p>Sets the transform to associate with this texture view.
     * The specified transform applies to the underlying surface
     * texture and does not affect the size or position of the view
     * itself, only of its content.</p>
     * 
     * <p>Some transforms might prevent the content from drawing
     * all the pixels contained within this view's bounds. In such
     * situations, make sure this texture view is not marked opaque.</p>
     * 
     * @param transform The transform to apply to the content of
     *        this view.
     * 
     * @see #getTransform(android.graphics.Matrix) 
     * @see #isOpaque() 
     * @see #setOpaque(boolean) 
     */
    public void setTransform(Matrix transform) {
        mMatrix.set(transform);
        mMatrixChanged = true;
        invalidateParentIfNeeded();
    }
[/quote] 能麻烦讲得详细点么,怎么样才能达到裁剪的效果,我只知道矩阵可以处理纹理的各种效果,可不知道怎么裁剪掉surfaceView的一部分不进行绘制啊
hn_刘潇 2015-09-14
  • 打赏
  • 举报
回复
引用 1 楼 x13945 的回复:
matrix

    /**
     * <p>Sets the transform to associate with this texture view.
     * The specified transform applies to the underlying surface
     * texture and does not affect the size or position of the view
     * itself, only of its content.</p>
     * 
     * <p>Some transforms might prevent the content from drawing
     * all the pixels contained within this view's bounds. In such
     * situations, make sure this texture view is not marked opaque.</p>
     * 
     * @param transform The transform to apply to the content of
     *        this view.
     * 
     * @see #getTransform(android.graphics.Matrix) 
     * @see #isOpaque() 
     * @see #setOpaque(boolean) 
     */
    public void setTransform(Matrix transform) {
        mMatrix.set(transform);
        mMatrixChanged = true;
        invalidateParentIfNeeded();
    }
hn_刘潇 2015-09-14
  • 打赏
  • 举报
回复
matrix
为了避免大家浪费时间,直接先看下面的 Gif,略大,请耐心点。看完后,若你觉得会需要到,那么就请听我继续。gif 链接 http://123.57.244.105:8081/commentthumb/GIF.gifgit显示,略大,请耐心GitHub 链接废话一句:这个显示只是其中一部分,重点是:FFmpeg Camera 的录制部分,所以,你的星星(star)也是一种更新通知 (我通知你)。https://github.com/af913337456/WeChatVideoView功能点如果你看完上面的gif图,你会发现如下几点功能 (Function list):1,直观的播放前,可以显示封面缩略图播放时,如果还没有本地缓存,那么先进行下载下载过程中,显示圆型区域进度效果下载后,播放完毕后可以循环播放播放已经播放过的,是具备本地缓存的,也就是既能播放网络,也能播放本地2,隐藏的低耗电量低内存占用无延迟图与视频切换低耦合,高内聚,几行代码接入,一共3个类解析直观的功能点,几乎就是和新版微信的一样,从朋友圈点击一个视频,然后进入到一个 Activity 页面进行加载以及播放。为什么低耗电量和低内存占用?因为采用的是 SurfaceView 而不是 TextureView,图与视频切换的切换延迟也是这个原因。在你的 Activity 中这样使用这样就会以 id 为 activity_main 的 Relativelayout 为父容器装载。因为要避免内存泄露,所以你还需要做完下面的一些步骤,不会超过6行代码。技术点 (可以不看)1,下载操作:自定义 AsyncTask。PS:AsyncTask 比 Thread handler 重量级却方便(回调进度),但是,如果是 即放即用,结束即销毁,那么,no need to think about this;2,视频播放组合拳: surfaceView mediaPlayersurfaceView 用作显示,mediaPlayer 用来解码两者关系: mediaPlayer 绑定 surfaceView。为什么不用 TextrueView?3,进度区域自定义 View,3个画笔绘制,一个圆,一个边,一个扇区。作者:林冠宏 / 指尖下的幽灵掘金:https://juejin.im/user/587f0dfe128fe100570ce2d8博客:http://www.cnblogs.com/linguanh/GitHub : https://github.com/af913337456/

80,360

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧