首页 编程 软件学院 查看内容

android条码扫描程序

2014-12-25 11:05 1012 0

摘要: 源码下载地址:地址1:https://github.com/alivebao/BarCodeReader地址2:http://download.csdn.net/detail/miaoyunzexia...
关键词: nbsp 布局 一个 android import ScanLineView View graphics 线性 函数

源码下载地址:地址1:https://github.com/alivebao/BarCodeReader地址2:http://download.csdn.net/detail/miaoyunzexiaobao/8297201参考链接:zxing入门:http://www.cnblogs.com/liuan/archive/2012/01/05/2312714.htmlBitmapLuminanceSource类实现:http://blog.csdn.net/xyz_fly/article/details/8089558目标:完成一个条码扫描程序,能识别出一维码和二维码,并将解析出来的结果显示出来效果图:扫描中-》扫描成功                     扫描成功后: 首先在布局上放置一个预览框,用于实时显示摄像头拍摄到的情况,并在其上绘制一条来回扫描的线条。之后在其下方放一个imageView,用于显示摄像头自动聚焦后获取的图片。实现:该Activity的整体布局为方向vertical的线性布局。该线性布局内嵌着一个帧布局和另一个线性布局。帧布局中先在底层防止了一个SurfaceView,用于显示摄像头预览图片,再在其上放置了一个自己实现的View类ScanLineView,该类继承自View,主要功能为在SurfaceView上绘制一条来回扫描的红色线条。下面的LinearLayout放置了一个ImageView,用于显示聚焦后获得的图片(程序自动对该图片进行解码)code:[html] view plaincopy<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:orientation="vertical"      tools:context=".MainActivity" >        <FrameLayout          android:layout_width="match_parent"          android:layout_height="0px"          android:layout_weight=".3" >            <SurfaceView              android:id="@+id/preview_view"              android:layout_width="fill_parent"              android:layout_height="fill_parent" />            <com.miao.barcodereader.ScanLineView              android:id="@+id/capture_viewfinder_view"              android:layout_width="fill_parent"              android:layout_height="fill_parent"              android:background="@android:color/transparent" />      </FrameLayout>        <LinearLayout          android:layout_width="match_parent"          android:layout_height="0px"          android:layout_weight=".7"          android:orientation="vertical" >            <ImageView              android:id="@+id/imageView"              android:layout_width="fill_parent"              android:layout_height="fill_parent"              android:src="@drawable/ic_launcher" />      </LinearLayout>    </LinearLayout>  ScanLineView类:继承自View类,重载其onDraw函数,在onDraw函数中间隔一段时间发送申请重绘屏幕的请求,drawLine函数的功能为每次被调用时绘制一条横坐标逐渐增加的红线。这个类要是嫌麻烦的话也可以不写,把上面布局文件中的ScanLineView控件删掉就行了,对程序功能没什么影响。code:[java] view plaincopypackage com.miao.barcodereader;    import android.content.Context;  import android.graphics.Canvas;  import android.graphics.Color;  import android.graphics.Paint;  import android.graphics.Rect;  import android.util.AttributeSet;  import android.view.View;    public class ScanLineView extends View{        private  声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系 [邮箱地址] 删除

路过

雷人

握手

鲜花

鸡蛋

最新评论

返回顶部