让二维条码扫描器具有识别汉字的能力(delphi)

1、将汉字编码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

var

  s: widestring;

  i, j: integer;

  tmpstr: string;

  c2: WideChar;

begin

  for j := 0 to Memo2.lines.count - 1 do

  begin

    tmpstr := '';

    s := Memo2.Lines[j];

    for i := 1 to length(s) do

    begin

      tmpstr := tmpstr + inttostr(ord(s[i])) + ',';      

    end;

  end;

  Memo1.Lines.Add(tmpstr + '#');

end;

2、根据汉字编码生成二维码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

const

  sFileName = 'QRCode.bmp';

var

  oBmp: TBitmap;

begin 

  CreateQRCode(AnsiToUtf8(memo1.Lines.Text), 013);

  if FileExists(sFileName) then

  begin

    oBmp := TBitmap.Create;

    oBmp.LoadFromFile(sFileName);

    image1.Picture.Assign(oBmp);

    FreeAndNil(oBmp);

  end;

end;

  

  

3、将编码转换成汉字(解码)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

var

  tmplist: TStringList;

  tmpstr: string;

  j, i: Integer;

  c2: WideChar;

begin

  try

    tmplist := TStringList.Create();

    tmpstr := Copy(Self.Edit1.Text, 0, Length(Self.Edit1.Text) - 1);

    tmplist := SplitString(tmpstr, ',');

    for j := 0 to tmplist.Count - 1 do

    begin

      if tmplist[j] <> '' then

      begin

        i := StrToInt(tmplist[j]);

        c2 := widechar(i);

        Memo1.Lines.Add(c2)

      end;

    end;

  finally

    FreeAndNil(tmplist);

  end;

end;

4、用到的splitstring函数:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

function SplitString(const Source, ch: string): TStringList;

var

  temp: string;

  i: Integer;

begin

  Result := TStringList.Create;

//如果是空自符串则返回空列表

  if Source = ''

    then exit;

  temp := Source;

  i := pos(ch, Source);

  while i <> 0 do

  begin

    Result.add(copy(temp, 0, i - 1));

    Delete(temp, 1, i);

    i := pos(ch, temp);

  end;

  Result.add(temp);

end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值