Two-dimensional code related content collection

Source: Internet
Author: User

1, Zbar Read

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

Zbar is a 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 12 8, Code 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 a pixels through the "canvas.pixels ()" property. In Firemonkey, this is not supported, and you had to use the SetPixel property of a Tbitmapdata instance.

Once the QR code is generated, to convert it to a bitmap image, in Firemonkey:

1234567891011121314151617181920212223242526272829303132333435363738 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 is able to make it work correctly.

I ' ve decided to use Timage and not tpaintbox as I am 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:

123456789101112131415 //refresh image. imgQRCode is a TImageimgQRCode.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 thentry  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 was used by default. There is the properties you need to set to ensure a bigger copy of your (small) QR code is drawn pixel-copy-perfect.

1234 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 is welcome (even more if you know how to resize a bitmap in Firemonkey on mobile without antialiasing)!

RELATED Links: http://zarko-gajic.iz.hr/generating-qr-codes-using-delphi-delphizxingqrcode-open-source-unit-by-debenu/

Two-dimensional code related content collection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.