从零开发一款相机APP 第七篇: Camera2相机 预览功能实现

news/2024/7/6 22:26:19
本课程内容由 @小驰笔记 出品,欢迎关注,获取更多交流信息~
欢迎访问个人博客:www.xiaochibiji.com
显示需要借助surface,一般采用surfaceview或者textureview;

相关重要流程:

1、自定义TextureView

private AutoFitTextureView mTextureView;

2、Activity OnResume的时候,判断mTextureView 当前状态。如果是available状态,则直接打开camera,否则设置surfaceTexture监听

if (mTextureView.isAvailable()) {            openCamera(mTextureView.getWidth(), mTextureView.getHeight()); } else {            mTextureView.setSurfaceTextureListener(mSurfaceTextureListener); }

3、surfaceTexture监听中,SurfaceTextureAvailable的时候,去执行opencamera的操作

privatefinal TextureView.SurfaceTextureListener mSurfaceTextureListener            = new TextureView.SurfaceTextureListener() {        @Override        public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {            openCamera( width, height);        }        @Override        public void onSurfaceTextureSizeChanged(SurfaceTexture texture, int width, int height) {            configureTransform(width, height);        }        @Override        public boolean onSurfaceTextureDestroyed(SurfaceTexture texture) {            returntrue;        }        @Override        public void onSurfaceTextureUpdated(SurfaceTexture texture) {        }    };

4、设置surface target

Surface surface = new Surface(texture);// We set up a CaptureRequest.Builder with the output Surface.mPreviewRequestBuilder		= mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);mPreviewRequestBuilder.addTarget(surface);

5、 创建会话中,传入surface

mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),                    new CameraCaptureSession.StateCallback() {}

相关视频持续录制中…

推荐阅读:

博客大更新_

关于我

今年,做好一件事情

一篇文章带你了解Android 最新Camera框架

深圳上班,

从事Android Camera相关软件开发工作,

记录生活和工作的点滴,

点击关注“小驰笔记”,期待和你相遇~


http://www.niftyadmin.cn/n/3745868.html

相关文章

从零开发一款相机APP 第六篇: Camera2相机 打开功能实现

本课程内容由 小驰笔记 出品,欢迎关注,获取更多交流信息~ 欢迎访问个人博客:www.xiaochibiji.com 流程图: 1、获取当前设备支持摄像头颗数 CameraManager manager (CameraManager) activity.getSystemService(Context.CAMERA_S…

从零开发一款相机 第五篇:Camera api1实现预览、拍照、录像功能

本课程内容由 小驰笔记 出品,欢迎关注,获取更多交流信息~ 欢迎访问个人博客:www.xiaochibiji.com这节课,我们主要讲解如果使用camera api1接口,实现预览、拍照以及录像功能。 目前市面上很大部分的APP,如果…

文字两行展示,超出部分显示为省略号

text-overflow: -o-ellipsis-lastline;overflow: hidden;text-overflow: ellipsis;display: -webkit-box;-webkit-line-clamp: 2;line-clamp: 2;-webkit-box-orient: vertical;

Ubuntu中使用python3.8

1 安装Python3.8 # 更新软件包 sudo apt update ​ # 安装python3.8 sudo apt install python3.82 安装虚拟环境 # 安装venv包 sudo apt install python3-venv3 创建虚拟环境 # 虚拟环境中的python环境默认是3.8 python3.8 -m venv my_env_python3.84 激活虚拟环境 # 激活…

工厂方法(Factory Pattern)

工厂方法模式定义:定义了一个创建对象的接口,但由子类决定要实例化的类是哪一个。工厂方法让类把实例化推迟到子类。(注:“决定”不是指模式允许子类本身在运行时做决定,而是指在编写创建者类时,不需要知道…

从零开发一款相机APP 第四篇: Camera 常用api和最新框架介绍

本课程内容由 小驰笔记 出品,欢迎关注,获取更多交流信息~ 欢迎访问个人博客:www.xiaochibiji.com这节课,我们主要来学习了解android camera相关api,以及大体看下android camera的最新框架。 一、android camera api介…

idea导入新maven项目后,修改idea的maven配置,不要用idea默认的

idea导入新maven项目后,修改maven的setting路径配置,不要用默认的 file>setting>搜索Maven 三个分别是maven安装路径,配置文件路径,本地Jar仓库路径

使用let's Encrypt给网站加入https同时支持http2

2019独角兽企业重金招聘Python工程师标准>>> 1.如果python版本是2.6请运行 yum install python-argparse.noarch 2.重点 下载脚本 wget https://raw.githubusercontent.com/xdtianyu/scripts/master/lets-encrypt/letsencrypt.conf wget https://raw.githubusercon…