hbuider+二维码扫描技术功能改进+

请把以下资料 转发给  同学们:


二维码扫描技术  参考网址:


https://www.2cto.com/kf/201607/522563.html
https://blog.csdn.net/u012843100/article/details/51433316
https://blog.csdn.net/qq_27626333/article/details/51815121
https://blog.csdn.net/qq_24754061/article/details/54943655


发送  mui技术参考文档


PPT 内容:  二维码是什么?  二维码扫描技术有哪些内容?  研究代码在手机上运行测试


-----------------------------------------


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Barcode Example</title>
<script type="text/javascript" >
// 扩展API加载完毕后调用onPlusReady回调函数 
document.addEventListener( "plusready", onPlusReady, false );
// 扩展API加载完毕,现在可以正常调用扩展API
function onPlusReady() {
  var e = document.getElementById("scan");
  e.removeAttribute( "disabled" );
}
// 从图片中扫描 
function scanImg() {
plus.barcode.scan( '_www/barcode.png', function (type,result) {
alert( "Scan success:("+type+")"+result );
}, function (error) {
alert( error.message );
} );
}
</script>
<style type="text/css">
*{
-webkit-user-select: none;
}
html,body{
margin: 0px;
padding: 0px;
height: 100%;
}
</style>
</head>
<body >
<input id="scan" type='button' disabled="disabled" οnclick='scanImg()' value='扫描图片'></input>
</body>
</html>




----------------------------------------------


interface plus.barcode.Barcode {
// Methods
function void start( options );
function void cancel();
function void setFlash( open );


// Events
function void onmarked();
function void onerror();
}




--------------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Barcode Example</title>
<script type="text/javascript" >
// 扩展API加载完毕后调用onPlusReady回调函数 
document.addEventListener( "plusready", onPlusReady, false );
// 扩展API加载完毕,现在可以正常调用扩展API
function onPlusReady() {
var e = document.getElementById("scan");
e.removeAttribute( "disabled" );
}
var scan = null;
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 startRecognize() {
scan = new plus.barcode.Barcode('bcid');
scan.onmarked = onmarked; 
}
function startScan() {
scan.start();
}
function cancelScan() {
scan.cancel();
}
function setFlash() {
scan.setFlash();
}
</script>
<style type="text/css">
*{
-webkit-user-select: none;
}
html,body{
margin: 0px;
padding: 0px;
height: 100%;
}
#bcid {
background:#0F0;
height:480px;
width:360px;
}
</style>
</head>
<body >
<input type='button' οnclick='startRecognize()' value='创建扫描控件' />
<input type='button' οnclick='startScan()' value='开始扫描' />
<input type='button' οnclick='cancelScan()' value='取消扫描' />
<input type='button' οnclick='setFlash()' value='开启闪光灯' />
<div id= "bcid"></div>
<input type='text' id='text'/>
</body>
</html>


----------------------------------
// 创建支持默认二维码类型的识别控件
var bc = new plus.barcode.Barcode( "barcode" );
// 创建支持
var filter = [plus.barcode.QR,plus.barcode.AZTEC];
var bc2 = new plus.barcode.Barcode( "barcode", filter );




---------------------------------------






二维码识别成功事件




void obj.onmarked = function ( type, code, file ) {
// loaded code 
}










--------------------------------------------


<!DOCTYPE html>
<html>


<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>他人创建的二维码扫描案例-1,不是我做的 ,可以运行</title>
<script src="js/mui.min.js"></script>
<link href="css/mui.min.css" rel="stylesheet" />
<script type="text/javascript" charset="utf-8">
mui.init();
</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" οnclick="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>












------------------------------------------------


<!doctype html>
<html>


<head>
<meta charset="UTF-8">
<title>可以测试运行的二维码扫描案例-1</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" />



<style type="text/css">
/*#bcid{
width: 80%;
height: 50%;
position: absolute;
background: #000000;
}
*/
#bcid{
width: 100%;
height: 50%;
position:;
background: red;
}

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>


<span class="mui-icon mui-icon-spinner-cycle mui-spin mui-pull-right" id="turnTheLight"></span>
<div id="bcid">   
    <!--盛放扫描控件的div-->  
</div>



<div class="mui-content-padded">
<button class="mui-btn mui-btn-block mui-btn-primary" id="login"> 扫描二维码 </button>
</div>
 
<script src="js/mui.min.js"></script>
<script type="text/javascript">
mui.init()
//var scan = null; //扫描对象
mui.plusReady(function() {
var login = document.getElementById("login");


login.addEventListener("tap", function() {


startRecognize();


});
})
</script>


<script type="text/javascript">
//将账号与密码保存到Localstore  
function startRecognize() {


try {
var filter;
//自定义的扫描控件样式
var styles = {
frameColor: "#29E52C",
scanbarColor: "#29E52C",
background: ""
}
//扫描控件构造
var 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);


};
</script>


</body>


</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值