二维码相关内容收集

1、zbar 读取

http://zbar.sourceforge.net/download.html

ZBar is an open source software suite for reading bar codes      from various sources, such as video streams, image files and raw      intensity sensors.  It supports many popular symbologies      (types of bar codes) including EAN-13/UPC-A, UPC-E, EAN-8, Code      128, Code 39, Interleaved 2 of 5 and QR Code.

2、ZxingQrcode

http://zarko-gajic.iz.hr/firemonkey-mobile-android-ios-qr-code-generation-using-delphi-xe-5-delphizxingqrcode/

In the VCL, the TCanvas class allows accessing single pixels through the “Canvas.Pixels()” property. In FireMonkey this is not supported and you have to use the SetPixel property of a TBitmapData instance.

Once the qr code is generated, to convert it to a bitmap image, in FireMonkey:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var
   QRCode: TDelphiZXingQRCode;
   Row, Column: Integer ;
   pixelColor : TAlphaColor;
   vBitMapData : TBitmapData;
   rSrc, rDest : TRectF;
   s : widestring ;
begin
   QRCode := TDelphiZXingQRCode . Create;
   try
     QRCode . Data := edtText . Text;
     QRCode . Encoding := TQRCodeEncoding(cmbEncoding . ItemIndex);
     QRCode . QuietZone := StrToIntDef(edtQuietZone . Text, 4 );
     QRCodeBitmap . SetSize(QRCode . Rows, QRCode . Columns);
     for Row := 0 to QRCode . Rows - 1 do
     begin
       for Column := 0 to QRCode . Columns - 1 do
       begin
         if (QRCode . IsBlack[Row, Column]) then
           pixelColor := TAlphaColors . Black
         else
           pixelColor := TAlphaColors . White;
 
         if QRCodeBitmap . Map(TMapAccess . maWrite, vBitMapData)  then
         try
           vBitMapData . SetPixel(Column, Row, pixelColor);
         finally
           QRCodeBitmap . Unmap(vBitMapData);
         end ;
       end ;
     end ;
   finally
     QRCode . Free;
   end ;
 
   //refresh image control imgQRCode is a TImage
   {code below}
end ;

Note: compare this with the VCL approach of TDelphiZXingQRCode usage.

 

VCL’s Canvas.StretchDraw to FMX’s Canvas.DrawBitmap

There’s no StrecthDraw in FMX’s Canvas class. There’s DrawBitmap. StretchDraw by default does no antialiasing. FMX does. So I had to play a little until I was able to make it work correctly.

I’ve decided to use TImage and not TPaintBox as I was simply not able to make TPictureBox in FireMonkey draw what I wanted :(

Using TImage, the code to get/display the generated QR Code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//refresh image. imgQRCode is a TImage
 
imgQRCode . Bitmap . SetSize(QRCodeBitmap . Width, QRCodeBitmap . Height);
 
rSrc := TRectF . Create( 0 , 0 , QRCodeBitmap . Width, QRCodeBitmap . Height);
rDest := TRectF . Create( 0 , 0 , imgQRCode . Bitmap . Width, imgQRCode . Bitmap . Height);
 
if imgQRCode . Bitmap . Canvas . BeginScene then
try
   imgQRCode . Bitmap . Canvas . Clear(TAlphaColors . White);
 
   imgQRCode . Bitmap . Canvas . DrawBitmap(QRCodeBitmap, rSrc, rDest, 1 );
finally
   imgQRCode . Bitmap . Canvas . EndScene;
end ;

Aliasing – Do Not Need It!

By default, in FMX, when using DrawBitmap to resize it, antialiasing is used by default. There are two properties you need to set to ensure a bigger copy of your (small) qr code is drawn pixel-copy-perfect.

1
2
3
4
begin
   imgQRCode . DisableInterpolation := true ;
   imgQRCode . WrapMode := TImageWrapMode . iwStretch;
end ;

In a FireMonkey Desktop application, this works as expected.

On FireMonkey Mobile it does not :(  – the resized image is still blurred (antialiasing used).

That’s it. QR Codes generation in FireMonkey – both desktop and mobile!

Download the FMX version of DelphiZXIngQRCode.pas: FMX-DelphiZXIngQRCode

Comments are welcome (even more if you know how to resize a bitmap in FireMonkey on mobile without antialiasing)!

 

相关链接:  http://zarko-gajic.iz.hr/generating-qr-codes-using-delphi-delphizxingqrcode-open-source-unit-by-debenu/

转载于:https://www.cnblogs.com/fanbbs/p/4298538.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值