Barcode修改二维码对中文的支持
Barcode2011版本, 在UnicodeIDE环境下原本二维码处理中文时有问题, 只读取了第一个字节转换, 所以中文会出错
修改psCodeStudio.pas文件,TpsQRCode.EncodePart函数
function TpsQRCode.EncodePart(const ToEncode:String; currMode: TpsQRMode):String; var i, j, k: integer; s, s1: String; k1, k2: integer; c: Char; lBytes: TBytes; begin i := 1; s := GetModeIndicator(FMicroQR, currMode, FUsedVersion); if currMode = QrBytes then begin lBytes := TEncoding.UTF8.GetBytes(ToEncode); s := s + IntegerToBits(Length(lBytes), GetNumberOfBitsIndicatorSize(FMicroQR, currMode, FUsedVersion)); end else begin lBytes := nil; s := s + IntegerToBits(Length(ToEncode), GetNumberOfBitsIndicatorSize(FMicroQR, currMode, FUsedVersion)); end; case currMode of QrNumeric: while i <= Length(ToEncode) do begin s1 := Copy(ToEncode, i, 3); k := 0; for j := 1 to Length(s1) do k := 10 * k + Ord(s1[j]) - Ord0; case Length(s1) of 1: s := s + IntegerToBits(k, 4); 2: s := s + IntegerToBits(k, 7); 3: s := s + IntegerToBits(k, 10); end; Inc(i, 3); end; QrAlphanumeric: while i <= Length(ToEncode) do begin c := ToEncode[i]; if (FNC1 <> fnc1None) and (Char(c) = GS1_GroupSeparator) then c := '%'; k1 := System.Pos(c, QR_AlphaTable) - 1; if k1 = -1 then begin s := ''; Exit; end; Inc(i); if i <= Length(ToEncode) then begin c := ToEncode[i]; if (FNC1 <> fnc1None) and (Char(c) = GS1_GroupSeparator) then c := '%'; k2 := Pos(c, QR_AlphaTable) - 1; if k2 = -1 then begin s := ''; Exit; end; s := s + IntegerToBits(45 * k1 + k2, 11); end else s := s + IntegerToBits(k1, 6); Inc(i); end; QrBytes: begin for i := Low(lBytes) to High(lBytes) do s := s + IntegerToBits(lBytes[i], 8); end; QrKanji: ; end; result := s; end;
以下为修改完的文件
https://files.cnblogs.com/files/lzl_17948876/psCodeStudio.rar
--------------------------------------------------------------------------------------------------
作者:黑暗煎饼果子
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
--------------------------------------------------------------------------------------------------