Barcode的一个实现案例
一、简介
Barcode模块管理条码扫描,提供常见的条码(二维码及一维码)的扫描识别功能,可调用设备的摄像头对条码图片扫描进行数据输入。通过plus.barcode可获取条码码管理对象。
二、实现的效果
三、实现 代码
<!doctype html> <html> <head> <meta charset="UTF-8"> <title></title> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <link href="css/mui.min.css" rel="stylesheet" /> <script src="js/mui.min.js"></script> <style type="text/css"> #bcid{ width: 100%; height: 100%; position: absolute; background: #000000; } html, body ,div{ height:100%; width: 100%; } .fbt{ color: #0E76E1; width: 50%; background-color: #ffffff; float: left; line-height: 44px; text-align: center; } </style> </head> <body> <header class="mui-bar mui-bar-nav" style="background-color: #ffffff;"> <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a> <h1 class="mui-title" style="color: #0E76E1;">物品二维码扫描</h1> <span class="mui-icon mui-icon-spinner-cycle mui-spin mui-pull-right" id="turnTheLight"></span> </header> <div id="bcid"> <!--盛放扫描控件的div--> </div> <div class="mui-bar mui-bar-footer" style="padding: 0px;"> <div class="fbt" onclick="scanPicture();">从相册选择二维码</div> <div class="fbt mui-action-back">取 消</div> </div> <script type="text/javascript"> scan = null;//扫描对象 mui.plusReady(function () { mui.init(); startRecognize(); }); function startRecognize(){ try{ var filter; //自定义的扫描控件样式 var styles = {frameColor: "#29E52C",scanbarColor: "#29E52C",background: ""} //扫描控件构造 scan = new plus.barcode.Barcode('bcid',filter,styles); scan.onmarked = onmarked; scan.onerror = onerror; scan.start(); //打开关闭闪光灯处理 var flag = false; document.getElementById("turnTheLight").addEventListener('tap',function(){ if(flag == false){ scan.setFlash(true); flag = true; }else{ scan.setFlash(false); flag = false; } }); }catch(e){ alert("出现错误啦:\n"+e); } }; function onerror(e){ alert(e); }; function onmarked( type, result ) { var text = ''; switch(type){ case plus.barcode.QR: text = 'QR: '; break; case plus.barcode.EAN13: text = 'EAN13: '; break; case plus.barcode.EAN8: text = 'EAN8: '; break; } alert( text + " : "+ result ); }; // 从相册中选择二维码图片 function scanPicture() { plus.gallery.pick(function(path){ plus.barcode.scan(path,onmarked,function(error){ plus.nativeUI.alert( "无法识别此图片" ); }); },function(err){ plus.nativeUI.alert("Failed: "+err.message); }); } </script> </body> </html>
三、做的过程中遇见的问题
a,div占满整个页面
1,此div宽高都为100%,父级元素的高度也为此(依次类推直至根节点),或者此div的position为absolute;
2,可采用js动态设置页面宽高
var height = window.innerHeight + 'px';//获取页面实际高度 var width = window.innerWidth + 'px'; document.getElementById("bcid").style.height= height; document.getElementById("bcid").style.width= width;
b,扫描控件有上下边距
采用填充黑色来淡化视觉上面的差异,未实际解决,(如果你解决的话,欢迎留言,谢谢)
总结
以上所述是小编给大家介绍的基于MUI框架使用HTML5实现的二维码扫描功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年09月21日
2024年09月21日
- 群星.1995-烧得厉害VOL.4两个世界【滚石】【WAV+CUE】
- 归龙潮中浦城区宝箱位置收集大全 中浦区宝箱解密攻略
- 黑神话悟空上品幽灯鬼精魄获取方法一览|上品幽灯鬼精魄收集攻略
- 《电锯糖心:RePOP》发售首日表现亮眼,玩家峰值超越《星鸣特攻》
- NewViennaOctet,ViennaWindSoloists-TheDeccaRecordings(2024)18CD[FLAC]-8
- 金梅子-《靓声妹3又见炊烟》[WAV+CUE]
- 杨阳《约定HQCDII》头版限量编号2024[WAV+CUE]
- 曝《黑神话:悟空》DLC明年推出 农历新年前后
- PS5日本涨价19% 索尼股价应声上涨2.7%
- 《黑神话》发行平台遭大规模网攻 外媒却鲜有报道
- 伍佰《爱你伍佰年 世纪典藏原音精选3CD》[WAV+CUE][2.3GB]
- 伍佰《爱情的尽头》[WAV+CUE][2.6GB]
- 伍佰 《光环摇滚之声DSD》[WAV+CUE][500MB]
- 王菲.1999-只爱陌生人【EMI百代】【WAV+CUE】
- 林美音.1993-酒后的心声【瑞华】【WAV+CUE】