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

Comments

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

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

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

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

    ReplyDelete
  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

    ReplyDelete
  6. An example in Delphi, pleaaaase

    ReplyDelete
  7. For developers who is still using the old ANSI Delphi versions I made a new release of the Quricol library http://delphi32.blogspot.com/2012/01/ansi-version-of-quricol-delphi-library.html

    ReplyDelete
  8. I published the Delphi example how to use the Quricol library: http://delphi32.blogspot.com/2012/01/quricol-delphi-sample.html

    ReplyDelete
  9. Thanks a lot Serhiy. You are an good man.

    Rossmery

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

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

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

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

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

    ReplyDelete
  15. I added contact form to my blog

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

    Thanks again:D


    Octavio.

    ReplyDelete
  17. hello

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

    kind regards

    Ersan YAKIT
    Application Developer

    ReplyDelete
  18. The source code is included in the archive in C++ folder

    ReplyDelete
  19. The new release of Quricol is available. Download: http://users.telenet.be/ws36637/download/quricol.zip

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

    ReplyDelete
  21. thank you Serhiy Perevoznyk


    Ersan YAKIT
    Application Developer

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

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

    ReplyDelete
  24. The new release of Quricol - the open source freeware QR code generator library is available for download. In this release I added the possibility for developers to choose the error correction level by themselves.

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

    ReplyDelete
  25. Hi
    I downloaded the recent version of the Quircol which you had shared here
    http://users.telenet.be/ws36637/download/quricol.zip

    I am using Delphi XE2 on a Win7 64Machine. The line

    TQRCode.GenerateBitmapFile('delphi1.bmp', 'http://delphi32.blogspot.com',4,3, QualityLow);

    is thrwoing an external exception as follows,
    External exception C06D007E.

    Please help..

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

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

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

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

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

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

    ReplyDelete
  32. Quricol is a pure Windows library, but you can uselibqrencode http://fukuchi.org/works/qrencode/index.html.en for your purposes

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

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

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

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

    Image1.Picture.Bitmap := generatedBitmap;

    ReplyDelete
  37. 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', 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.

    ReplyDelete
  38. I figured it out I changed my calls to:
    TQRCode.GenerateBitmapFile('delphi1.bmp', 'http://delphi32.blogspot.com', 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 :-)

    ReplyDelete
  39. This comment has been removed by the author.

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

    ReplyDelete
  41. @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.

    ReplyDelete

Post a Comment

Popular posts from this blog

Quricol 2.0 - QR Code generator

Diswy - freeware application to show or hide desktop icons