Camera相机开发详解

ec6abee6ec4793199ca76b18edcf1a19.gif

和你一起终身学习,这里是程序员Android

经典好文推荐,通过阅读本文,您将收获以下知识点:

一、 SurfaceView 、Surface 、 SurfaceHolder
二、Camera 概览
三、总结

前言

  • 上一篇文章介绍了如何调用系统相机进行拍照裁剪等功能,一般情况下这些已经能满足我们的需求了。但是在有些场景和特殊需求下,比如要进行人脸检测、要不间断地抓取多张照片等等,那就需要使用原生Camera来进行开发啦

  • 这里并不打算讲如何用代码去实现,而是先给小伙们介绍相关的知识点,等对这些知识有了大致了解后在动手去写,这样既能有目的的去写又能加深对知识点的理解

  • 本篇文章主要给大家讲解进行Camera开发需要用到的类和方法,以及在开发过程中遇到的方向问题的分析


进行Camra开发主要用到了以下两个类:

  1. Camera

  2. SurfaceView (当然也可以是TextureView,本文我们使用SurfaceView)

这两者的关系如下图:

34c689f42ca64a3cb0b4fe018d6e58eb.png

image

一、 SurfaceView 、Surface 、 SurfaceHolder

关系图

59fe021d089ce9b93a0211f0b6f124cf.png

image

Surface

什么是Surface?源码中是这样描述的:

* Handle onto a raw buffer that is being managed by the screen compositor.
 *
 * <p>A Surface is generally created by or from a consumer of image buffers (such as a
 * {@link android.graphics.SurfaceTexture}, {@link android.media.MediaRecorder}, or
 * {@link android.renderscript.Allocation}), and is handed to some kind of producer (such as
 * {@link android.opengl.EGL14#eglCreateWindowSurface(android.opengl.EGLDisplay,android.opengl.EGLConfig,java.lang.Object,int[],int) OpenGL},
 * {@link android.media.MediaPlayer#setSurface MediaPlayer}, or
 * {@link android.hardware.camera2.CameraDevice#createCaptureSession CameraDevice}) to draw
 * into.</p>

简单翻译一下,大概意思就是:

Surfaces是用来处理屏幕显示内容合成器所管理的原始缓存区的工具。它通常由图像缓冲区的消费者来创建(如:SurfaceTexture,MediaRecorder),然后被移交给生产者(如:MediaPlayer)或者是显示到其上(如:CameraDevice)

SurfaceHolder

源码描述:

* Abstract interface to someone holding a display surface.  Allows you to
 * control the surface size and format, edit the pixels in the surface, and
 * monitor changes to the surface.  This interface is typically available
 * through the {@link SurfaceView} class.

简单翻译一下:

一个抽象接口,给持有surface的对象使用。它可以控制surface的大小和格式,编辑surface中的像素,以及监听surface的变化。这个接口通常通过SurfaceView类获得

SurfaceHolder中有一个Callbcak接口,它有3个回调方法

  • surfaceCreated(SurfaceHo

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员Android

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值