查看: 3503|回复: 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   下载,
以及 也可以直接下载下面的压缩包...
[fold=
简单   
var b = Bitmap.qrcode("www.baidu.com")  
高级
var b = Bitmap.qrcode({ "text":"www.baidu.com" , "width": 100,"height":100 })]
[pre lang="javascript"]
//=============================================================================
// Bitmap_qrcode.js
//=============================================================================
/*:
* @plugindesc 二维码
* @author wangwang
*  
* @help
* 参考 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 })
*
*
*/


(function(){
        Bitmap.qrcode = function(options) {
                // if options is string,
                if( typeof options === 'string' ){
                        options        = { text: options };
                }               
                var text = options.text || ""
                var width        =        options.height || 256
                var height        =        options.height  ||  256
                var background    =  options.background  || "#ffffff"
                var foreground   =  options.background || "#000000"
                var type = ( "type" in  options )?  options.type : -1
                var corr=  ( "corr" in  options )?options.corr: QRErrorCorrectLevel.H
                // create the qrcode itself
                var qrcode        = new QRCode(type, corr);
                qrcode.addData(text);
                qrcode.make();
                // create canvas element
                var bitmap        =  new Bitmap(width,height)
                 
                // compute tileW/tileH based on options.width/options.height
                var tileW        = width  / qrcode.getModuleCount();
                var tileH        = height / qrcode.getModuleCount();
                // draw in the canvas
                for( var row = 0; row < qrcode.getModuleCount(); row++ ){
                        for( var col = 0; col < qrcode.getModuleCount(); col++ ){
                                color = qrcode.isDark(row, col) ? foreground : background;
                                var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW));
                                var h = (Math.ceil((row+1)*tileW) - Math.floor(row*tileW));
                                bitmap.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h,color);  
                        }       
                }
                // return just built canvas
                return bitmap;
        };
})(); [/pre]
[/fold]
【20160313_1.0】qrcode.zip (7.35 KB, 下载次数: 57)
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部