二维码zxing源码分析(一)camera部分
首先,我们先把zxing的源代码给下载下来,这个网上有很多,我下载的是2.3的,不得不说这个谷歌提供的包包含的功能还是很全面的。
public static Camera open() {
// 获取摄像头的数量
int numCameras = Camera.getNumberOfCameras();
//如果没有找到相机则退出
if (numCameras == 0) {
Log.w(TAG, "No cameras!");
return null;
}
int index = 0;
while (index < numCameras) {
//初始化相机信息类
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
//获取相机的信息
Camera.getCameraInfo(index, cameraInfo);
//判断是否是后置摄像头
if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
break;
}
index++;
}
//打开相机
Camera camera;
if (index < numCameras) {
Log.i(TAG, "Opening camera #" + index);
camera = Camera.open(index);
} else {
Log.i(TAG, "No camera facing back; returning camera #0");
camera = Camera.open(0);
}
return camera;
}
从这个方法中把摄像头打开
void initFromCameraParameters(Camera camera) {
//获取相机的参数
Camera.Parameters parameters = camera.getParameters();
WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = manager.getDefaultDisplay();
//构造一个点
Point theScreenResolution = new Point();
//给点进行赋值,屏幕的宽和高 Resolution分辨率的意思
display.getSize(theScreenResolution);
screenResolution = theScreenResolution;
Log.i(TAG, "Screen resolution: " + screenResolution);
cameraResolution = findBestPreviewSizeValue(parameters, screenResolution);
Log.i(TAG, "Camera resolution: " + cameraResolution);
}
public synchronized void openDriver(SurfaceHolder holder) throws IOException {
Camera theCamera = camera;
if (theCamera == null) {
theCamera = OpenCameraInterface.open();
if (theCamera == null) {
throw new IOException();
}
camera = theCamera;
}
//设置摄像头预览功能
theCamera.setPreviewDisplay(holder);
//初始化执行的操作
if (!initialized) {
initialized = true;
//初始化相机的参数,选择最佳的预览分辨率
configManager.initFromCameraParameters(theCamera);
if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
requestedFramingRectWidth = 0;
requestedFramingRectHeight = 0;
}
}
Camera.Parameters parameters = theCamera.getParameters();
String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save these, temporarily
try {
//设置必要的参数,包括焦点,闪光灯等
configManager.setDesiredCameraParameters(theCamera, false);
} catch (RuntimeException re) {
// Driver failed
Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
// Reset:
if (parametersFlattened != null) {
parameters = theCamera.getParameters();
parameters.unflatten(parametersFlattened);
try {
theCamera.setParameters(parameters);
configManager.setDesiredCameraParameters(theCamera, true);
} catch (RuntimeException re2) {
// Well, darn. Give up
Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
}
}
}
}
<SurfaceView android:id="@+id/preview_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/> <com.google.zxing.client.android.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" />
二维码zxing源码分析(一)camera部分的更多相关文章
- 二维码zxing源码分析(五)精简代码
由于工作的需要,我并不是需要二维码扫描的所有的功能,我只是需要扫一扫,并显示出来图片和url就行,于是我们就要精简代码了,源码已经分析完了,精简起来就方便多了,源码分析请看 二维码zxing源码分析( ...
- 二维码zxing源码分析(四)wifi部分
前三个部分的地址是:ZXING源码分析(一)CAMERA部分 . zxing源码分析(二)decode部分.zxing源码分析(三)result.history部分 前面三篇文章基本上已经把zxin ...
- 二维码zxing源码分析(二)decode部分
在上一篇博客中分析了zxing怎么打开摄像头,并且扫描结果,那么扫描之后的数据呢,是不是就要解析了呢,那我们看一下zxing怎么解析这个数据的. 上一篇博客地址ZXING源码 ...
- 二维码扫描 zxing源码分析(三)result、history部分
前两个部分的地址是:ZXING源码分析(一)CAMERA部分 . zxing源码分析(二)decode部分 下面我们来看第三部分 result包下面有很多的类,其中的核心类是 com.google. ...
- zxing源码分析——QR码部分
Android应用横竖屏切换 zxing源码分析——DataMatrix码部分 zxing源码分析——QR码部分 2013-07-10 17:16:03| 分类: 默认分类 | 标签: |字号大中 ...
- 一步步实现windows版ijkplayer系列文章之二——Ijkplayer播放器源码分析之音视频输出——视频篇
一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...
- Alink漫谈(二十) :卡方检验源码解析
Alink漫谈(二十) :卡方检验源码解析 目录 Alink漫谈(二十) :卡方检验源码解析 0x00 摘要 0x01 背景概念 1.1 假设检验 1.2 H0和H1是什么? 1.3 P值 (P-va ...
- 方维 o2o app源码出售
方维 o2o app源码出售 方维o2oapp源码出售 1.本人官方5万购买,现把方维o2o app 源码低价出售: 2.包括网站源码本地搭建包成功提供指导 3.包括网站说明文档,不包含app说明文档 ...
- Ubuntu12.04下zxing源码编译
1.下载zxing源码 git clone https://github.com/15903016222/zxing-cpp.git 2.安装依赖工具cmake sudo apt-get instal ...
随机推荐
- Tomcat创建虚拟目录和程序热部署
虚拟目录的设置 方法一:在${tomcat安装目录}/conf/Catalina/localhost目录下添加与web应用同名的xml配置文件,这里站点名称为test为例子. test.xml内容:& ...
- javascrpt随笔
function member(name, gender) { this.name = name; this.gender = gender; this.display = display; //指定 ...
- IAR USING PRE- AND POST-BUILD ACTIONS
Using pre-build actions for time stamping If necessary, you can specify pre-build and post-build act ...
- Java常见排序算法之折半插入排序
在学习算法的过程中,我们难免会接触很多和排序相关的算法.总而言之,对于任何编程人员来说,基本的排序算法是必须要掌握的. 从今天开始,我们将要进行基本的排序算法的讲解.Are you ready?Let ...
- 广州项目实施步骤III_练习使用Keepalive保证HaProxy的高可用性
CentOS6.4 配置HAProxy+Keepalived 安装HAProxy请参考 http://www.cnblogs.com/kgdxpr/p/3272861.html 安装Keepali ...
- URL是什么?
URL是统一资源定位符,有时也被俗称为网页地址. 如同在网络上的门牌,是因特网上标准的资源的地址(Address). 在因特网的历史上,统一资源定位符的发明是一个非常基础的步骤.统一资源定位符的语法是 ...
- Oracle 自己主动诊断资料档案库 (ADR)、自己主动诊断工作流、ADRCI工具
1.自己主动诊断工作流: 通过一个始终处于打开状态的内存中跟踪工具,数据库组件能够在第一次出现严重错误故障时捕获诊断数据.系统将自己主动维护一个称为"自己主动诊断资料档案库"的特殊 ...
- [Angular2 Router] Build Angular 2 Navigation with routerLink
Angular 2 navigation is configured using the routerLink directive. The routerLink directive behaves ...
- GXPT(一)——UI设计
通过长时间的积淀.TGB再次開始GXPT模式,JAVA版..NET版两条线同一时候进行. 纯面向对象的底层架构的搭建:easyUI+MVC的界面设计:工作流的再次雄起.云平台的构想:Confluenc ...
- andorid
js内存泄露 三分面加七分水 —— 十分糊涂 膝盖上打瞌睡 —— 自己靠自己 不当家,不知柴米贵:不生子,不知父母恩. 水落现石头,日久见人心. sqllite http://wenku.baidu. ...