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).
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..
LikeLike
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.
LikeLike
Thank you!!
LikeLike
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).
LikeLike
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.
LikeLike
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
LikeLike
An example in Delphi, pleaaaase
LikeLike
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
LikeLike
I published the Delphi example how to use the Quricol library: http://delphi32.blogspot.com/2012/01/quricol-delphi-sample.html
LikeLike
Thanks a lot Serhiy. You are an good man.
Rossmery
LikeLike
What kind of license are you providing with this code? can i embed it in a commercial product?
LikeLike
(Posting again because i forgot to enable follow-up emails)
LikeLike
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.
LikeLike
If you put LGPL in the import units the it couldn't be used in commercial projects. May i sugesst MPL? 😉
LikeLike
Yes, I agree with MPL 🙂
LikeLike
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; ………
…………..
…………..
…………..
…………..
LikeLike
I added contact form to my blog
LikeLike
Hey. Just to say tank you for your lib, it works perfect , I really appreciate it
Thanks again:D
Octavio.
LikeLike
hello
can u share with us source code of quricol32.dll?
kind regards
Ersan YAKIT
Application Developer
LikeLike
The source code is included in the archive in C++ folder
LikeLike
The new release of Quricol is available. Download: http://users.telenet.be/ws36637/download/quricol.zip
LikeLike
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
LikeLike
thank you Serhiy Perevoznyk
Ersan YAKIT
Application Developer
LikeLike
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
LikeLike
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.
LikeLike
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
LikeLike
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..
LikeLike
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.
LikeLike
Have same problem as Arun Joseph P.
External exception C06D007E.
On Create Bitmap File or Just BitMap.
Delphi 2010
Windows Xp,7 x32/x64
LikeLike
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.
LikeLike
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
LikeLike
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
LikeLike
hi Im trying to use quricol on linux. What should I do with widows.h?
Do you have some *.so versions?
LikeLike
Quricol is a pure Windows library, but you can uselibqrencode http://fukuchi.org/works/qrencode/index.html.en for your purposes
LikeLike
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.
LikeLike
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
LikeLike
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.
LikeLike
I use delphi 2010
LikeLike
When you generated the bitmap image using TQRCode.GetBitmapImage assign the resulted bitmap to your Timage.Picture.Bitmap property.
Image1.Picture.Bitmap := generatedBitmap;
LikeLike
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.
LikeLike
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 🙂
LikeLike
This comment has been removed by the author.
LikeLike
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.
LikeLike
@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.
LikeLike
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?
LikeLike
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.
LikeLike
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
LikeLike