在研究zxing的过程中,脑袋中一直有个疑惑,那个相机并没有拍照,它是怎么获取图像的

带着这个疑惑查看Camera源码

Camera源码中有这样一个接口:

public interface PreviewCallback
{
/**
* Called as preview frames are displayed. This callback is invoked
* on the event thread {@link #open(int)} was called from.
*
* <p>If using the {@link android.graphics.ImageFormat#YV12} format,
* refer to the equations in {@link Camera.Parameters#setPreviewFormat}
* for the arrangement of the pixel data in the preview callback
* buffers.
*
* @param data the contents of the preview frame in the format defined
* by {@link android.graphics.ImageFormat}, which can be queried
* with {@link android.hardware.Camera.Parameters#getPreviewFormat()}.
* If {@link android.hardware.Camera.Parameters#setPreviewFormat(int)}
* is never called, the default will be the YCbCr_420_SP
* (NV21) format.
* @param camera the Camera service object.
*/
void onPreviewFrame(byte[] data, Camera camera);
};

Called as preview frames are displayed. This callback is invoked on the event thread open(int) was called from.

其中这个  “open(int) ”很关键

android.hardware.Camera.PreviewCallback

Callback interface used to deliver copies of preview frames as they are displayed.

See Also:
setPreviewCallback(Camera.PreviewCallback)
setOneShotPreviewCallback(Camera.PreviewCallback)
setPreviewCallbackWithBuffer(Camera.PreviewCallback)
startPreview()

选这其中一个打开:

/**
* <p>Installs a callback to be invoked for the next preview frame in
* addition to displaying it on the screen. After one invocation, the
* callback is cleared. This method can be called any time, even when
* preview is live. Any other preview callbacks are overridden.</p>
*
* <p>If you are using the preview data to create video or still images,
* strongly consider using {@link android.media.MediaActionSound} to
* properly indicate image capture or recording start/stop to the user.</p>
*
* @param cb a callback object that receives a copy of the next preview frame,
* or null to stop receiving callbacks.
* @see android.media.MediaActionSound
*/
public final void setOneShotPreviewCallback(PreviewCallback cb) {
mPreviewCallback = cb;
mOneShot = true;
mWithBuffer = false;
if (cb != null) {
mUsingPreviewAllocation = false;
}
setHasPreviewCallback(cb != null, false);
}

单触发模式,只要预览ok,就会启动回调函数

onPreviewFrame(byte[] data, Camera camera)

把当前的视窗类的Frame的信息装到byte[] data ,这样程序就得到预览窗口的图像数据。

其他的两个是连续触发模式,接近视频流的模式,每一帧都会返给数组,摄像机程序的实现底层肯定调用这个函数。

Android相机是如何获取到图像的的更多相关文章

  1. Android相机、相册获取图片显示并保存到SD卡

    Android相机.相册获取图片显示并保存到SD卡 [复制链接]   电梯直达 楼主    发表于 2013-3-13 19:51:43 | 只看该作者 |只看大图  本帖最后由 happy小妖同学 ...

  2. Android中调用系统的相机和图库获取图片

    //--------我的主布局文件------很简单---------------------------------<LinearLayout xmlns:android="http ...

  3. 【腾讯优测干货分享】Android 相机预览方向及其适配探索

    本文来自于腾讯bugly开发者社区,未经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/583ba1df25d735cd2797004d 由于Android系统的开放策略 ...

  4. Android相机开发那些坑

    版权声明:本文由王梓原创文章,转载请注明出处: 文章原文链接:https://www.qcloud.com/community/article/168 来源:腾云阁 https://www.qclou ...

  5. 原来这样就可以开发出一个百万量级的Android相机

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由QQ空间开发团队发表于云+社区专栏 最近我负责开发了一个跟Android相机有关的需求,新功能允许用户使用手机摄像头,快速拍摄特定尺寸 ...

  6. Android 多种方式正确的载入图像,有效避免oom

    图像载入的方式:        Android开发中消耗内存较多一般都是在图像上面.本文就主要介绍如何正确的展现图像降低对内存的开销,有效的避免oom现象. 首先我们知道我的获取图像的来源一般有三种源 ...

  7. iOS 从相机或相册获取图片并裁剪

    今天遇到一个用户头像上传的问题,需要从相册或者相机中读取图片.代码很简单,抽取关键部分,如下: //load user image - (void)UesrImageClicked { UIActio ...

  8. Android根据图片Uri获取图片path绝对路径的几种方法【转】

    在Android 编程中经常会用到Uri转化为文件路径,如我们从相册选择图片上传至服务器,一般上传前需要对图片进行压缩,这时候就要用到图片的绝对路径. 下面对我开发中uri转path路径遇到的问题进行 ...

  9. [Android相机]通过手机摄像头识别环境亮度(转)

    源: [Android相机]通过手机摄像头识别环境亮度 iOS利用摄像头获取环境光感参数

随机推荐

  1. 用webpack搭建react开发环境

    安装插件: npm install react react-dom babel-loader babel-core babel-preset-react babel-preset-es2015 配置w ...

  2. MVC特性路由的提供机制

    回顾:传统路由是如何提供的? 我们知道最终匹配的路由数据是保存在RouteData中的,而RouteData通常又是封装在RequestContext中的,他们是在哪里被创建的呢?没错,回到了UrlR ...

  3. AngularJS1.X学习笔记1-整体看看

    听说 明天是愚人节,这与我有什么关系呢!我可 不想被愚弄,但是但是,我这么笨怎么才能不被愚弄呢?左思右想,我决定从现在开始闭关,闭关干啥哩?学习!学习AngularJS.以前学习过Angular的,不 ...

  4. 1 IDEA 安装 及 IDEA开发 spring的环境搭建

    摘要: 主要讲解使用 IDEA 开发 Spring MVC 的环境搭建,Maven的简单教学. 参考1:https://my.oschina.net/gaussik/blog/385697 参考2:h ...

  5. Bar 3D 和Pie 3D的统计图形

    最近在做一个关于图形统计的界面,主要用到的是Dev控件ChartControl(功能很强大,能解决基本和复杂图形统计问题). ChartControl主要有Diagram.Series.Legend三 ...

  6. c#遍历文件夹获得所有文件

    在c#中,想要获得一个文件夹下的所有子目录以及文件十分简单. 首先,获取目录的情况下,DirectoryInfo.GetDirectories():获取目录(不包含子目录)的子目录,返回类型为Dire ...

  7. less学习笔记(一)

    less的写法如下 .content { ul{ list-style: none; } li{ height: 25px; line-height: 25px; padding-left: 15px ...

  8. Ranking Relevance小结

    Ranking Relevance是搜索排序算法的各个影响因子中相当重要的一个部分.对于Ranking Relevance的计算,过去的技术往往分为两个大的方向:Click Behavior和Text ...

  9. android studio 2.3 下载地址

      android studio下载:  Windows+SDK:(1.8GB)| Windows(428 MB) | Linux    idea  win.exe  win.zip 序号 名称 中文 ...

  10. 对Qt下对话服务器客户端的总结(MyTcpServer与MyTcpClient)

    在汇文培训老师给讲了这个例子.讲的挺好的 Qt编写聊天服务器与客户端主要用到下面两个类: QTcpSocket --- 处理连接的 QTcpServer --- 处理服务器,对接入进行响应,创建每个链 ...