Quricol – QR code generator library

Quricol is an open source freeware QR code generator library for C++, Microsoft .NET and Delphi based on qrencode – QR Code encoder by Kentaro Fukuchi.The library contains methods to save the generated image to Bitmap or PNG file or generate images on-fly and save it to the stream. Both 32 and 64 bits compiled versions available along with source code.

Download: http://users.telenet.be/ws36637/download/quricol.zip

A QR code (abbreviated from Quick Response code) is a type of matrix barcode (or two-dimensional code).

GitHub: https://github.com/perevoznyk/quricol

47 thoughts on “Quricol – QR code generator library

  1. Exemptor December 5, 2011 / 11:55

    In Delphi7, GetBitmap return image, but if image scan he return abrakadarba 🙂
    I'll try text “1234567890”.

    And GenerateBitmap, GeneratePng doesn't save file.

    Sorry for my english..

    Like

  2. Serhiy Perevoznyk December 5, 2011 / 12:43

    The code is provided for Unicode Delphi versions and Delphi 7 is still Ansi.

    The code for Delphi with Ansi strings:

    unit QuricolCode;

    interface

    uses

    Windows, SysUtils, Classes, Graphics;

    type

    TQRCode = class

    public

    class procedure GenerateBitmap(const FileName : WideString; const Text : WideString; Margin : integer = 4; PixelSize : integer = 3);

    class procedure GeneratePng(const FileName : WideString; const Text : WideString; Margin : integer = 4; PixelSize : integer = 3);

    class function GetBitmap(const Text : WideString; Margin : integer = 4; PixelSize : integer = 3) : TBitmap;

    class procedure GetPng(Stream : TStream; const Text : WideString; Margin : integer = 4; PixelSize : integer = 3);

    end;

    implementation

    procedure GeneratePNGW(fileName: PWChar; text : PWChar; margin : integer; size : integer); stdcall; external 'quricol32.dll';

    function GetHBitmapW(text : PWChar; margin : integer; size : integer) : HBITMAP; stdcall; external 'quricol32.dll';

    procedure GenerateBMPW(fileName: PWChar; text : PWChar; margin : integer; size : integer); stdcall; external 'quricol32.dll';

    procedure GetPNGW(text : PWChar; margin : integer; size : integer; var bufSize : integer; out ppvBits : PByte); stdcall; external 'quricol32.dll';

    procedure DestroyBuffer(Buffer : PByte); stdcall; external 'quricol32.dll';

    { TQRCode }

    class procedure TQRCode.GenerateBitmap(const FileName, Text: WideString; Margin,

    PixelSize: integer);

    begin

    GenerateBMPW(PWChar(FileName), PWChar(Text), Margin, PixelSize);

    end;

    class procedure TQRCode.GeneratePng(const FileName, Text: WideString; Margin,

    PixelSize: integer);

    begin

    GeneratePNGW(PWChar(FileName), PWChar(Text), Margin, PixelSize);

    end;

    class function TQRCode.GetBitmap(const Text: WideString; Margin,

    PixelSize: integer): TBitmap;

    var

    Bmp : HBITMAP;

    DIB: TDIBSection;

    ScreenDC : THandle;

    DC : THandle;

    begin

    Bmp := GetHBitmapW(PWChar(Text), Margin, PixelSize);

    GetObject(Bmp, SizeOf(DIB), @DIB);

    Result := TBitmap.Create();

    Result.Width := DIB.dsBmih.biWidth;

    Result.Height := DIB.dsBmih.biHeight;

    Result.PixelFormat := pf32bit;

    ScreenDC := GetDC(0);

    DC := CreateCompatibleDC(ScreenDC);

    SelectObject(DC, Bmp);

    ReleaseDC(0, ScreenDC);

    BitBlt(Result.Canvas.Handle, 0, 0, Result.Width, Result.Height, DC, 0, 0, SRCCOPY);

    DeleteDC(DC);

    DeleteObject(Bmp);

    end;

    class procedure TQRCode.GetPng(Stream: TStream; const Text: WideString; Margin,

    PixelSize: integer);

    var

    size : integer;

    i : integer;

    buffer : PByte;

    ps : PByte;

    begin

    size := 0;

    GetPNGW(PWChar(Text), Margin, PixelSize, size, buffer);

    if (size > 0) then

    begin

    ps := buffer;

    for I := 0 to size – 1 do

    begin

    Stream.Write(ps^, 1);

    inc(ps);

    end;

    DestroyBuffer(buffer);

    end;

    end;

    end.

    Like

  3. MarioSteffen December 10, 2011 / 11:32

    Dear Serhiy,
    I am also using Delphi 7 and the unit returned an invalid typecast error when I called GenerateBMPW.
    I changed the PWChar to PChar and String to WideString and the compilation is ok.
    The problems are
    1) the text I tryed was '12345' and when I read the bitmap, I received chinese characters;
    2) how can I generate multi-line text codes ? I need codes with at least 12 lines and +/- 400 bytes (total, not per line).

    Like

  4. Serhiy Perevoznyk December 10, 2011 / 16:42

    Maybe for Delphi 7 is better way to leave the functions declaration as-is (use PChar and string types), but replace the exported functions names from “W” version to “A” version, so use GenerateBMPA in place of GenerateBMPW.
    For generating the multiline code you can insert #13 at the end of the line, I guess.

    Like

  5. Luis Enrique Banda Valdivia January 3, 2012 / 23:19

    Hi all
    Thanks for this contribution into Delphi.

    I use D6 and cannot understand this code: I use the following:
    var
    wPar: array[0..254] of Char;
    begin
    StrPCopy(wPar,'ab.bmp');
    wQRCode:=TQRCode.create;
    wQRCode.GenerateBitmap(wPar,'1'+#13, 20, 3);

    But, get a bmp with name: ??? I have to rename for show. Please Serhiy can put an example. Please.

    Luis Enrique

    Like

  6. John Villar January 26, 2012 / 20:19

    What kind of license are you providing with this code? can i embed it in a commercial product?

    Like

  7. John Villar January 26, 2012 / 20:20

    (Posting again because i forgot to enable follow-up emails)

    Like

  8. Serhiy Perevoznyk January 27, 2012 / 09:56

    The library is based on qrencode library as I mentioned in the description: http://fukuchi.org/works/qrencode/manual/index.html
    qrencode is distributed under GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or any later version. I am not sure but maybe I must to follow the same license? If not then the code is just free with no limitation from my side.

    Like

  9. John Villar January 27, 2012 / 13:15

    If you put LGPL in the import units the it couldn't be used in commercial projects. May i sugesst MPL? 😉

    Like

  10. krzysiek February 9, 2012 / 13:25

    I have modified code to load library dynamically. This allows you to run a program when there is no library. All code unfortunately does not fit in the comment and I can't find email contact to author.

    unit QuricolCode;

    interface

    uses
    Windows, SysUtils, Classes, Graphics, Dialogs;

    type
    TQRCode = class
    public
    class procedure GenerateBitmap(const FileName : string; const Text : string; Margin : integer = 4; PixelSize : integer = 3);
    class procedure GeneratePng(const FileName : string; const Text : string; Margin : integer = 4; PixelSize : integer = 3);
    class function GetBitmap(const Text : string; Margin : integer = 4; PixelSize : integer = 3) : TBitmap;
    class procedure GetPng(Stream : TStream; const Text : string; Margin : integer = 4; PixelSize : integer = 3);
    end;

    implementation

    { TQRCode }

    class procedure TQRCode.GenerateBitmap(const FileName, Text: string; Margin,
    PixelSize: integer);
    type
    TGenerateBMPWProc = procedure (fileName: PWChar; text : PWChar; margin : integer; size : integer); stdcall;
    var
    dllHandle : cardinal;
    generateBMPWProc : TGenerateBMPWProc;
    begin
    dllHandle := LoadLibrary('quricol32.dll');
    if dllHandle <> 0 then
    begin
    try
    @generateBMPWProc := GetProcAddress(dllHandle, 'GenerateBMPW');
    if Assigned (generateBMPWProc) then
    generateBMPWProc(PWChar(FileName), PWChar(Text), Margin, PixelSize)
    else
    ShowMessage('”GenerateBMPW” procedure not found');
    finally
    FreeLibrary(dllHandle);
    end;
    end
    else
    begin
    ShowMessage('quricol32.dll not found / not loaded');
    end;
    end;

    class procedure TQRCode.GeneratePng(const FileName, Text: string; Margin,
    PixelSize: integer);
    type
    TGeneratePNGWProc = procedure (fileName: PWChar; text : PWChar; margin : integer; size : integer); stdcall;
    var
    dllHandle : cardinal;
    generatePNGWProc : TGeneratePNGWProc;
    begin
    dllHandle := LoadLibrary('quricol32.dll');
    if dllHandle <> 0 then
    begin
    try
    @generatePNGWProc := GetProcAddress(dllHandle, 'GeneratePNGW');
    if Assigned (generatePNGWProc) then
    generatePNGWProc(PWChar(FileName), PWChar(Text), Margin, PixelSize)
    else
    ShowMessage('”GeneratePNGW” procedure not found');
    finally
    FreeLibrary(dllHandle);
    end;
    end
    else
    begin
    ShowMessage('quricol32.dll not found / not loaded');
    end;
    end; ………
    …………..
    …………..
    …………..
    …………..

    Like

  11. Octavio February 28, 2012 / 21:58

    Hey. Just to say tank you for your lib, it works perfect , I really appreciate it

    Thanks again:D

    Octavio.

    Like

  12. Ersan YAKIT March 9, 2012 / 08:14

    hello

    can u share with us source code of quricol32.dll?

    kind regards

    Ersan YAKIT
    Application Developer

    Like

  13. Mike April 11, 2012 / 02:35

    Very well done – works like a charm!!

    Unfortunately the error correction level is set to low, but i need it set to high (=QR_ECLEVEL_H). It seems as if this is hard-coded into the library (call to QRcode_encodeString) and can not be changed from outside.

    Is there any way to change this? Or could you just provide a library compiled with the error correction level set to high?

    Many thanks in advance
    /mike

    Like

  14. Ersan YAKIT May 4, 2012 / 12:43

    thank you Serhiy Perevoznyk

    Ersan YAKIT
    Application Developer

    Like

  15. Gabeszosz July 3, 2012 / 22:04

    Hi there!

    I'm using Delphi XE2 and everything seems to work fine so far. However, changing the hard-coded EC level to QR_ECLEVEL_H you've recently carried out is a very unfortunate change in my opinion. Most developers would like to get the most compact code possible which is achieved by using QR_ECLEVEL_L.

    I just want to ask if the old version (which had the QR_ECLEVEL_L setting hardcoded) is still available somewhere for download. I'd prefer it when generating QR codes for my own purpose.

    Thanks in advance,

    – Gabeszosz

    Like

  16. Serhiy Perevoznyk July 4, 2012 / 07:13

    Hello,
    I received the requests to change the error correction level to the different values. I can't make it right for everybody, but I included the full source code, so if the different value is needed for your project just change it and compile the library by yourself. It's only one line of code to be modified.

    Like

  17. чел челкоФ September 3, 2012 / 16:34

    Hi, I use delphi xe2.
    And work with quricol32.dll
    Please tell me how to use function GetHBitmap.
    If text more than 7065 characters, function return nil.

    Like

  18. Люда September 21, 2012 / 06:52

    Have same problem as Arun Joseph P.
    External exception C06D007E.
    On Create Bitmap File or Just BitMap.
    Delphi 2010
    Windows Xp,7 x32/x64

    Like

  19. Serhiy Perevoznyk September 21, 2012 / 08:47

    This code means that your application can't load quricol.dll

    1. You forgot to copy quricol.dll to your application folder

    2. You copied the wrong version (x64 in place of x32) of the dll.

    Like

  20. Unknown December 5, 2012 / 08:51

    NET Code Generator for C ++ DLL

    Hi,

    Thank you fro your contribution and I am looking for the working samples or links of .NET Code Generator from C++ DLL where included Structure, unsigned char * so on.

    So far, I didn't see any solutions in google search and I hope some one will advise me to get the best for me.

    Thanks and best regards

    Like

  21. Andreas Schachtner January 17, 2013 / 20:19

    Hello and thank you for this QR-Code-Thingy. 😉

    I use it with Delphi DX2 and it works fine, but it leaks Memory (Canvas, Brushes and so on). I use only the class function TQRCode.GetBitmapImage

    Like

  22. Victor David Flores January 27, 2013 / 18:15

    hi Im trying to use quricol on linux. What should I do with widows.h?
    Do you have some *.so versions?

    Like

  23. Victor David Flores January 27, 2013 / 20:58

    Tanks!!!
    I went there and I notice that libqrencode is a C libary, so I have to mix it with c++ by using:
    #ifdef __cplusplus
    extern “C” { …. bla bla bla

    but looking at libqrencode.h I notice that it actually starts in that way.

    I wonder if I still have to mix the code on c++, or it's all ready done?
    How ever I always got “undefined reference to `QRcode_encodeString'”
    (probably because is not mixed properly)

    I rely appreciate your advice.

    Like

  24. Serhiy Perevoznyk January 28, 2013 / 19:05

    Quricol is C++ library, but based on libqrencode code. I modified libqrencode code and my version is included with the sources of Qurirol. Maybe it can help you

    Like

  25. Gakwaya Daniel April 2, 2013 / 07:32

    Hello Serhiy,
    Thanks for this amazing piece of work.I want to use it to generate QR code in my VCL Delphi application but can not figure out how to get the generated image in a TImage for example so it can be seen on my form.I feel this should be basic but can't quite nail it down.Any help would be appreciated.
    Dan.

    Like

  26. Serhiy Perevoznyk April 2, 2013 / 10:40

    When you generated the bitmap image using TQRCode.GetBitmapImage assign the resulted bitmap to your Timage.Picture.Bitmap property.

    Image1.Picture.Bitmap := generatedBitmap;

    Like

  27. Gakwaya Daniel April 3, 2013 / 01:52

    Thanks for the response,I did what you said and I can load Images saved in the project directory,however When I try to load the image generated by the library like this:
    TQRCode.GenerateBitmapFile('delphi1.bmp', 'http://delphi32.blogspot.com&#39;, QualityLow);
    Form1.Image1.Picture.Bitmap.LoadFromFile('delphi1.bmp');

    I get the following error:
    [DCC Error] LoadImage.dpr(14): E2010 Incompatible types: 'Integer' and 'TErrorCorretion'

    I know I did something wrong somewhere and I would appreciate your help.Thanks.

    Like

  28. Gakwaya Daniel April 3, 2013 / 02:07

    I figured it out I changed my calls to:
    TQRCode.GenerateBitmapFile('delphi1.bmp', 'http://delphi32.blogspot.com&#39;, 1);
    Form1.Image1.Picture.Bitmap.LoadFromFile('delphi1.bmp');

    and it worked,I just provided the index of the quality I want in the quality enumerated type.In case somebody runs into the same problem.Again you really did a great job Serhiy.Thanks 🙂

    Like

  29. Gökhan May 18, 2013 / 13:03

    This comment has been removed by the author.

    Like

  30. Gökhan May 18, 2013 / 13:08

    Hi;

    How i change barcode image color? for example set background color to transparent or green. Set barcode color to red etc.

    thank you for your help.

    Like

  31. Serhiy Perevoznyk May 20, 2013 / 10:46

    @Gökhan

    Hi,
    This functionality is not implemented in the library. It can generate only black on white images. As a workaround you can replace the black pixels of the resulting image with other color. I think this is an interesting problem and I will do the changes to the library to make possible the color selection.

    Like

  32. Morgan Jeong November 1, 2016 / 06:08

    Thank you for sharing good library.

    Is there any sample code how to use it?

    I am trying it on my c++ project.

    Yes, i know you made it base on libqrencode.

    But, the interfaces of it is different from libqrencode owns.

    for example :

    void WINAPI GeneratePNGW(LPWSTR fileName, LPWSTR text, int margin, int size, int level);

    It might a function to generation QR code. However, there is void returning.

    How can i get the resulting?

    Like

    • Serhiy Perevoznyk November 15, 2016 / 07:34

      The function GeneratePNG creates PNG file with the specified file name. Basically, all functions of Quricol generate QR code images in different formats: PNG, JPEG, BMP. If you need QR code matrix, then you have to use libqrencode.

      Like

  33. ZoranG January 22, 2019 / 20:26

    Dear Serhiy,
    Many thanks for the the great QR code library.
    It works well with VB6, but sometimes it closes the application without any message (the program that calls it simply disappears).
    In development environment sometimes it just shows quricol32.dll library does not exits.

    Declaration:
    Public Declare Sub QRCodeQPNG _
    Lib “quricol32.dll” _
    Alias “GeneratePNGW” ( _
    ByVal FileName As Long, _
    ByVal Text As Long, _
    ByVal Margin As Long, _
    ByVal Size As Long, _
    ByVal Level As TErrorCorrection)

    Call:
    QRCodeQPNG StrPtr(ss), StrPtr(Me.fsSN), 3, 5, QualityHigh

    What could be the solution to the issue?

    Best regards!
    Zoran

    Like

Leave a reply to Serhiy Perevoznyk Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.