批处理制作二维码生成器

批处理制作二维码生成器,第1张

这个程序不能直接支持 Unicode, 同样不能直接支持任何双字节或多字节字符(包括汉字), 但可以用十六进制转码的方式生成包含 Unicode (或其他任何编码)字符的二维码图形.

如果数据含有UTF-8 Unicode 字符时, 在数据头部加上 BOM (\xEF\xBB\xBF) 即可.

例如:
\xEF\xBB\xBF\xE6\xB1\x89\xE5\xAD\x97
上面的代码表示中文字符 "汉字"

任何 ASCII 字符(\x00 到 \xFF)都可以用十六进制转码方式输入, 也可以用明文输入(如果可以的话), 十六进制转码用 "\x" 开头, 后跟两位十六进制.
例如: \x20 表示空格

纠错等级有4级可选: L,M,Q,H

掩码图形有 8 种可选: 0 到 7 的整数.

已更正的问题: 版本20141113, 当数据中含有双引号时, 有可能导致程序退出.

测试于 Win7 64 位 及 XP 32 位

REM If you want to rewrite the registry to automatically set the console font size to 8X8 pixels, please un-remark the next line.
REM %1 @goto :initCON
@echo off & chcp 437 & mode 200, 200
echo;
echo; QRCODE.CMD
echo;
echo; Author neorobin -- Rewritten in CMD Batch @ Nov. 12, 2014
echo;
echo; Author davidshimjs -- QRCode for Javascript library
echo; See http://www.d-project.com/
echo; See http://jeromeetienne.github.com/jquery-qrcode/
echo;
echo; ---------------------------------------------------------------------
echo; QRCode for JavaScript
echo;
echo; Copyright (c) 2009 Kazuhiko Arase
echo;
echo; URL: http://www.d-project.com/
echo;
echo; Licensed under the MIT license:
echo; http://www.opensource.org/licenses/mit-license.php
echo;
echo; The word "QR Code" is registered trademark of
echo; DENSO WAVE INCORPORATED
echo; http://www.denso-wave.com/qrcode/faqpatent-e.html
echo;
echo; ---------------------------------------------------------------------
echo;
REM ************************************************************
REM *
REM *            Main Program
REM *
REM ************************************************************
REM If you want to clear some environment variables to speed up running, you can un-remark the next line.
call :clearVars
setlocal enabledelayedexpansion
call :initGlobalVars
call :quickShow
:main.loop
 REM If the data contains Unicode UTF-8 characters, you must add the BOM data header (\xEF\xBB\xBF).
 REM set "BOM=\xEF\xBB\xBF"
 echo;
 set /p "data=Input data:"
 if "!data!"=="" goto :main.loop
 set "errorCorrectLevel="
 set /p "t=Choose a error correct level (L/M/Q/H):"
 for %%a in (L:1 M:0 Q:3 H:2) do for /f "tokens=1,2 delims=:" %%v in ("%%a") do if /i "%t%"=="%%v" set "errorCorrectLevel=%%w"
 if "%errorCorrectLevel%"=="" set "errorCorrectLevel=1"
 REM A - Auto, [0..7] - spec, else random
 set /p "mp=Choose a mask pattern between 0 and 7 :"
 if /i "!mp!"=="A" (
  set "maskPattern="
 ) else if "!mp!" geq "0" (
  if "!mp!" leq "7" (
   set /a "maskPattern = !mp:~0,1!"
  ) else (
   set "mp=r"
  )
 ) else (
  set "mp=r"
 )
 if "!mp!"=="r" (
  set /a "maskPattern = !random! & 7"
 )
 call :QRCode.makeCode data errorCorrectLevel maskPattern
goto :main.loop
exit
REM ************************************************************
REM *
REM *            Functions
REM *
REM ************************************************************
:QRCode.makeCode data errorCorrectLevel maskPattern
setlocal enabledelayedexpansion
 echo; & echo;QRCode.makeCode & echo;
 set "data=!%~1!"
 set /a "errorCorrectLevel = %~2"
 set "maskPattern=!%~3!"
 set data
 set errorCorrectLevel
 set maskPattern
 set "oQRCodeModel.dataList="
 call :_getTypeNumber TypeNumber data errorCorrectLevel
 REM If the initial size of the console is too small to display a large size QR Code image,
 REM you can un-remark the next line to auto resize the console window.
 REM call :autoResizeScr typeNumber 20
 set typeNumber
 call :QRCodeModel.addData oQRCodeModel.dataList oQRCodeModel.dataCache data
 set oQRCodeModel.dataList
 call :QRCodeModel.make oQRCodeModel typeNumber errorCorrectLevel maskPattern
 call :paint oQRCodeModel.modules oQRCodeModel.moduleCount
endlocal
exit /b
REM end of :QRCode.makeCode
REM ***
:QRCodeModel.make oQRCodeModel typeNumber errorCorrectLevel specifiedMaskPattern
setlocal enabledelayedexpansion
set "oQRCodeModel.dataList=!%~1.dataList!"
set "oQRCodeModel.dataCache=!%~1.dataCache!"
set /a "typeNumber = %~2, errorCorrectLevel = %~3"
set "BestMaskPattern=!%~4!"
if "!BestMaskPattern!"=="" (
 call :QRCodeModel.getBestMaskPattern oQRCodeModel typeNumber errorCorrectLevel BestMaskPattern
)
title QRCODE.CMD typeNumber: %typeNumber%, errorCorrectLevel: %errorCorrectLevel%, BestMaskPattern: 
本文经用户投稿或网站收集转载,如有侵权请联系本站。