Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

1 MONTH VIP - 5$; 3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
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 N0body, Feb 25, 2014.

  1. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator 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

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block