查看: 3575|回复: 0

[原创发布] bitmap 二维码 基于 jquery-qrcode

[复制链接]
梦石
0
星屑
1232
在线时间
1017 小时
注册时间
2011-4-30
回帖
1464
发表于 2016-3-13 20:36:28 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 汪汪 于 2016-7-24 10:55 编辑

原来的是 canvas 等格式,如果 mv使用的话不好用,所以参考原来的写了个 bitmap 版本....
其实也没什么用.......
.......

需要 qrcode.js 请到 https://github.com/jeromeetienne/jquery-qrcode   下载,
以及 也可以直接下载下面的压缩包...

简单   
var b = Bitmap.qrcode("www.baidu.com")  
高级
var b = Bitmap.qrcode({ "text":"www.baidu.com" , "width": 100,"height":100 })


  1. //=============================================================================
  2. // Bitmap_qrcode.js
  3. //=============================================================================
  4. /*:
  5. * @plugindesc 二维码
  6. * @author wangwang
  7. *  
  8. * @help
  9. * 参考 [url]https://github.com/jeromeetienne/jquery-qrcode[/url]
  10. *
  11. * 简单设置
  12. * var b = Bitmap.qrcode("www.baidu.com")
  13. *
  14. * 高级设置
  15. * var b = Bitmap.qrcode({ "text":"www.baidu.com" , "width": 100,"height":100 })
  16. *
  17. *
  18. */


  19. (function(){
  20.         Bitmap.qrcode = function(options) {
  21.                 // if options is string,
  22.                 if( typeof options === 'string' ){
  23.                         options        = { text: options };
  24.                 }               
  25.                 var text = options.text || ""
  26.                 var width        =        options.height || 256
  27.                 var height        =        options.height  ||  256
  28.                 var background    =  options.background  || "#ffffff"
  29.                 var foreground   =  options.background || "#000000"
  30.                 var type = ( "type" in  options )?  options.type : -1
  31.                 var corr=  ( "corr" in  options )?options.corr: QRErrorCorrectLevel.H
  32.                 // create the qrcode itself
  33.                 var qrcode        = new QRCode(type, corr);
  34.                 qrcode.addData(text);
  35.                 qrcode.make();
  36.                 // create canvas element
  37.                 var bitmap        =  new Bitmap(width,height)
  38.                  
  39.                 // compute tileW/tileH based on options.width/options.height
  40.                 var tileW        = width  / qrcode.getModuleCount();
  41.                 var tileH        = height / qrcode.getModuleCount();
  42.                 // draw in the canvas
  43.                 for( var row = 0; row < qrcode.getModuleCount(); row++ ){
  44.                         for( var col = 0; col < qrcode.getModuleCount(); col++ ){
  45.                                 color = qrcode.isDark(row, col) ? foreground : background;
  46.                                 var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW));
  47.                                 var h = (Math.ceil((row+1)*tileW) - Math.floor(row*tileW));
  48.                                 bitmap.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h,color);  
  49.                         }       
  50.                 }
  51.                 // return just built canvas
  52.                 return bitmap;
  53.         };
  54. })();
复制代码


【20160313_1.0】qrcode.zip (7.35 KB, 下载次数: 57)
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部