prc.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  5. <meta charset="utf-8">
  6. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  7. <meta content="yes" name="apple-mobile-web-app-capable">
  8. <meta content="black" name="apple-mobile-web-app-status-bar-style">
  9. <meta content="telephone=no" name="format-detection">
  10. <title>Web QrCode Test</title>
  11. <script type="text/javascript" src="jsqrcode-master/src/jquery.min.js" charset="utf-8"></script>
  12. <script type="text/javascript" src="jsqrcode-master/src/grid.js" charset="utf-8"></script>
  13. <script type="text/javascript" src="jsqrcode-master/src/version.js" charset="utf-8"></script>
  14. <script type="text/javascript" src="jsqrcode-master/src/detector.js" charset="utf-8"></script>
  15. <script type="text/javascript" src="jsqrcode-master/src/formatinf.js" charset="utf-8"></script>
  16. <script type="text/javascript" src="jsqrcode-master/src/errorlevel.js" charset="utf-8"></script>
  17. <script type="text/javascript" src="jsqrcode-master/src/bitmat.js" charset="utf-8"></script>
  18. <script type="text/javascript" src="jsqrcode-master/src/datablock.js" charset="utf-8"></script>
  19. <script type="text/javascript" src="jsqrcode-master/src/bmparser.js" charset="utf-8"></script>
  20. <script type="text/javascript" src="jsqrcode-master/src/datamask.js" charset="utf-8"></script>
  21. <script type="text/javascript" src="jsqrcode-master/src/rsdecoder.js" charset="utf-8"></script>
  22. <script type="text/javascript" src="jsqrcode-master/src/gf256poly.js" charset="utf-8"></script>
  23. <script type="text/javascript" src="jsqrcode-master/src/gf256.js" charset="utf-8"></script>
  24. <script type="text/javascript" src="jsqrcode-master/src/decoder.js" charset="utf-8"></script>
  25. <script type="text/javascript" src="jsqrcode-master/src/qrcode.js" charset="utf-8"></script>
  26. <script type="text/javascript" src="jsqrcode-master/src/findpat.js" charset="utf-8"></script>
  27. <script type="text/javascript" src="jsqrcode-master/src/alignpat.js" charset="utf-8"></script>
  28. <script type="text/javascript" src="jsqrcode-master/src/databr.js" charset="utf-8"></script>
  29. </head>
  30. <body>
  31. <div class="booth">
  32. <video id="video" width="400" height="400"></video>
  33. <canvas id='canvas' width='400' height='400'></canvas>
  34. </div>
  35. <!--<div id="mmm"></div>-->
  36. <!--<canvas id="qr-canvas" width="400" height="400"></canvas>-->
  37. <script>
  38. //初始化媒体对象
  39. var c=0;
  40. var video = document.getElementById('video'),
  41. canvas = document.getElementById('canvas'),
  42. // img = document.getElementById('img'),
  43. vendorUrl = window.URL || window.webkitURL;
  44. //媒体对象
  45. navigator.getMedia = navigator.getUserMedia ||
  46. navagator.webkitGetUserMedia ||
  47. navigator.mozGetUserMedia ||
  48. navigator.msGetUserMedia;
  49. navigator.getMedia({
  50. video: { facingMode: { exact: "environment" } }, //使用摄像头对象
  51. audio: false //不适用音频
  52. }, function(strem){
  53. console.log(strem);
  54. video.src = vendorUrl.createObjectURL(strem);
  55. // alert(video.src);
  56. video.play();
  57. }, function(error) {
  58. //error.code
  59. console.log(error);
  60. });
  61. //启动定时器
  62. setTimeout("actionP(null)","5000");
  63. //定时器
  64. function actionP(data){
  65. // alert(data);
  66. // alert(1);
  67. if(data==null){
  68. Screenshot()
  69. }else{
  70. if(data!=null & data!="error decoding QR Code"){//识别出数据
  71. // if(data.indexOf("http")!=-1){
  72. // window.location.href=data;
  73. // }else
  74. // document.write("<div style='font-size: 40pt;'>"+data+"</div>");
  75. alert(data);
  76. }else{//没有数据循环十次
  77. c++;
  78. if(c<10){
  79. setTimeout("actionP(null)","5000");
  80. }
  81. }
  82. }
  83. }
  84. function Screenshot(){//截取图像
  85. // var imgData = getContext('2d').drawImage(video, 0, 0, 400, 400).toDataURL("image/png");
  86. canvas.getContext('2d').drawImage(video, 0, 0, 400, 400);
  87. var imgData = canvas.toDataURL("image/png");
  88. load(imgData);
  89. // img.src=imgData;
  90. }
  91. ////////////////////////////////////////识别二维码////////////////////////////////////////////
  92. function dragenter(e) {
  93. e.stopPropagation();
  94. e.preventDefault();
  95. }
  96. function dragover(e) {
  97. e.stopPropagation();
  98. e.preventDefault();
  99. }
  100. function drop(e) {
  101. e.stopPropagation();
  102. e.preventDefault();
  103. var dt = e.dataTransfer;
  104. var files = dt.files;
  105. }
  106. function load(name)
  107. {
  108. // initCanvas(400,400);
  109. //识别二维码并回调方法
  110. qrcode.callback = actionP;
  111. qrcode.decode(name);
  112. }
  113. function initCanvas(ww,hh)//创建画板
  114. {
  115. gCanvas = document.getElementById("qr-canvas");
  116. gCanvas.addEventListener("dragenter", dragenter, false);
  117. gCanvas.addEventListener("dragover", dragover, false);
  118. gCanvas.addEventListener("drop", drop, false);
  119. var w = ww;
  120. var h = hh;
  121. gCanvas.style.width = w + "px";
  122. gCanvas.style.height = h + "px";
  123. gCanvas.width = w;
  124. gCanvas.height = h;
  125. gCtx = gCanvas.getContext("2d");
  126. gCtx.clearRect(0, 0, w, h);
  127. imageData = gCtx.getImageData( 0,0,400,400);
  128. }
  129. </script>
  130. </body>
  131. </html>