Last active
May 22, 2019 08:14
-
-
Save ShinoharaTa/afa2fe567f4ba12dc8dc99b66da75bc7 to your computer and use it in GitHub Desktop.
jQuery QR Codeの問題点と解決 ref: https://qiita.com/Shino3/items/8373e4c96a354d6c38cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#tipQR").html(""); | |
$("#tipQR").qrcode({ width: 240, height: 240, text: "Shino3(e)" }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compute tileW/tileH based on options.width/options.height | |
- var tileW = options.width / qrcode.getModuleCount(); | |
- var tileH = options.height / qrcode.getModuleCount(); | |
+ var tileW = options.width / (qrcode.getModuleCount() + 8); | |
+ var tileH = options.height / (qrcode.getModuleCount() + 8); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// draw in the canvas | |
- for( var row = 0; row < qrcode.getModuleCount(); row++ ){ | |
- for( var col = 0; col < qrcode.getModuleCount(); col++ ){ | |
- ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background; | |
- var w = (Math.ceil((col+1)*tileW) - Math.floor(col*tileW)); | |
- var h = (Math.ceil((row+1)*tileH) - Math.floor(row*tileH)); | |
- ctx.fillRect(Math.round(col*tileW),Math.round(row*tileH), w, h); | |
- } | |
- } | |
+ for (var row = 0; row < (qrcode.getModuleCount() + 8); row++) { | |
+ for (var col = 0; col < (qrcode.getModuleCount() + 8); col++) { | |
+ if ((row < 4) || (row >= (qrcode.getModuleCount() + 4))) { | |
+ ctx.fillStyle = options.background; | |
+ } | |
+ else if ((col < 4) || (col >= (qrcode.getModuleCount() + 4))) | |
+ { | |
+ ctx.fillStyle = options.background; | |
+ } | |
+ else | |
+ { | |
+ ctx.fillStyle = qrcode.isDark(row - 4, col - 4) ? options.foreground : options.background; | |
+ } | |
+ var w = (Math.ceil((col + 1) * tileW) - Math.floor(col * tileW)); | |
+ var h = (Math.ceil((row + 1) * tileH) - Math.floor(row * tileH)); | |
+ ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h); | |
+ } | |
+ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment