1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Generating Qr Codes with delphi

Discussion in 'Delphi Programming' started by AdminDF, Feb 25, 2014.

  1. AdminDF
    Online

    AdminDFAdminDF is a Verified Member Delphifan Staff Member DF Staff

    [​IMG]

    Using the Google Chart Tools / Image Charts (aka Chart API) you can easily generate QR codes, this kind of images are a special type of two-dimensional barcodes. They are also known as hardlinks or physical world hyperlinks.
    The QR Codes store up to 4,296 alphanumeric characters of arbitrary text. QR codes can be read by an optical device with the appropriate software. Such devices range from dedicated QR code readers to mobile phones.
    All do you need to generate a QrCode is make a get request to this URI
    http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=M&chl=Go+Delphi+Go
    And the response will be a image (by default PNG, you can change the output format to gif adding a parameter like this chof=gif).
    in this page you can find more info about the parameters to generate a Qr Code using the Google Chart API.
    If you wanna encode more of 2000 chars do you need make a post request (this up to you).
    finally the very basic delphi source to create a Qr Code. does not exist much to comment because is very easy.

    Code:
    uses
     PngImage,
     HTTPApp,
     WinInet;
     
    type
    TQrImage_ErrCorrLevel=(L,M,Q,H);
     
    const
    UrlGoogleQrCode='http://chart.apis.google.com/chart?chs=%dx%d&cht=qr&chld=%s&chl=%s';
    QrImgCorrStr   : array [TQrImage_ErrCorrLevel] of string=('L','M','Q','H');
     
    procedure WinInet_HttpGet(const Url: string;Stream:TStream);
    const
    BuffSize = 1024*1024;
    var
      hInter   : HINTERNET;
      UrlHandle: HINTERNET;
      BytesRead: DWORD;
      Buffer   : Pointer;
    begin
      hInter := InternetOpen('', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
      if Assigned(hInter) then
      begin
        Stream.Seek(0,0);
        GetMem(Buffer,BuffSize);
        try
            UrlHandle := InternetOpenUrl(hInter, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
            if Assigned(UrlHandle) then
            begin
              repeat
                InternetReadFile(UrlHandle, Buffer, BuffSize, BytesRead);
                if BytesRead>0 then
                 Stream.WriteBuffer(Buffer^,BytesRead);
              until BytesRead = 0;
              InternetCloseHandle(UrlHandle);
            end;
        finally
          FreeMem(Buffer);
        end;
        InternetCloseHandle(hInter);
      end
    end;
     
    //this function return a Stream (PngImage inside) with a Qr code.
    procedure GetQrCode(Width,Height:Word;Correction_Level:TQrImage_ErrCorrLevel;const Data:string;StreamImage : TMemoryStream);
    Var
     EncodedURL  : string;
    begin
      EncodedURL:=Format(UrlGoogleQrCode,[Width,Height,QrImgCorrStr[Correction_Level],HTTPEncode(Data)]);
      WinInet_HttpGet(EncodedURL,StreamImage);
    end;

    [​IMG]

    Download Source Code Here
     
    george likes this.
  2. frjd
    Offline

    frjd DF Member

    RE:

    This also work fine - and offline: https://github.com/debenu/DelphiZXingQRCode/blob/master/Source/DelphiZXIngQRCode.pas
    Android version: http://zarko-gajic.iz.hr/firemonkey-mobile-android-ios-qr-code-generation-using-delphi-xe-5-delphizxingqrcode/
     

Share This Page