在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)在界面上显示解码后的数据
更多相关文章
- “罗永浩抖音首秀”销售数据的可视化大屏是怎么做出来的呢?
- Nginx系列教程(三)| 一文带你读懂Nginx的负载均衡
- 不吹不黑!GitHub 上帮助人们学习编码的 12 个资源,错过血亏...
- android显示png图片,原来透明的地方都变成黑色的了
- Android(安卓)图片文件夹区别
- 格式化字符串长度,超出部分显示省略号,区分汉字跟字母
- android studio上imageloader初探
- Android通过URL获取网络资源
- 2011.10.09——— android ImageView放大缩小(2)