在Android上使用ZXing识别条码 二次开发笔记 (2)

1、在CaptureActivityHandler类里方法:

public void handleMessage(Message message)

接收对图片解码后的结果,如果界面成功则进入下面分支

case R.id.decode_succeeded:

Log.d(TAG, "Got decode succeeded message");
state = State.SUCCESS;
Bundle bundle = message.getData();
Bitmap barcode = bundle == null ? null :
(Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);
activity.handleDecode((Result) message.obj, barcode);

2、调用CaptureActivity类handleDecode-> private void handleDecodeInternally(Result rawResult, Bitmap barcode)

//格式

TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
formatTextView.setText(rawResult.getBarcodeFormat().toString());

//类型

ResultHandler resultHandler = ResultHandlerFactory.makeResultHandler(this, rawResult);
TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
typeTextView.setText(resultHandler.getType().toString());

//时间 这个就无所谓了

DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
String formattedTime = formatter.format(new Date(rawResult.getTimestamp()));
TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
timeTextView.setText(formattedTime);

那条形码的值如何获得呢? rawResult.getText();即可获得。

进行结果解码结果解析,解析结果例如:

图片+ 条形码的值:978771151622121

格式 EAN_13

类型 ISBN

时间 2011

其中条形码值和类型,格式这三个数据就是使用zxing图片解码最后得到的数据。

3、总结

zxing条形码扫描的工作流程:

1)启动相机,在间隔很短的时间内连续拍照

2)调用图片解码把拍到在图片进行解码

3)当解码出结果时,解码器返回成功结果和数据

4)在界面上显示解码后的数据

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值