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).

Update 11.09.2013:

Quricol 2.0 is available for download. More information about this version on http://delphi32.blogspot.com/2013/09/quricol-20-qr-code-generator.html

Advertisements

46 thoughts on “Quricol – QR code generator library

  1. 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. 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. 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. 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. 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. 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

  7. 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

  8. 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

  9. 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

  10. 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

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. @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

  17. 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

    1. 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s