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: https://github.com/perevoznyk/quricol
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 :)
ReplyDeleteI'll try text "1234567890".
And GenerateBitmap, GeneratePng doesn't save file.
Sorry for my english..
The code is provided for Unicode Delphi versions and Delphi 7 is still Ansi.
ReplyDeleteThe 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.
Thank you!!
ReplyDeleteDear Serhiy,
ReplyDeleteI 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).
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.
ReplyDeleteFor generating the multiline code you can insert #13 at the end of the line, I guess.
Hi all
ReplyDeleteThanks 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
An example in Delphi, pleaaaase
ReplyDeleteFor 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
ReplyDeleteI published the Delphi example how to use the Quricol library: http://delphi32.blogspot.com/2012/01/quricol-delphi-sample.html
ReplyDeleteThanks a lot Serhiy. You are an good man.
ReplyDeleteRossmery
What kind of license are you providing with this code? can i embed it in a commercial product?
ReplyDelete(Posting again because i forgot to enable follow-up emails)
ReplyDeleteThe library is based on qrencode library as I mentioned in the description: http://fukuchi.org/works/qrencode/manual/index.html
ReplyDeleteqrencode 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.
If you put LGPL in the import units the it couldn't be used in commercial projects. May i sugesst MPL? ;)
ReplyDeleteYes, I agree with MPL :)
ReplyDeleteI 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.
ReplyDeleteunit 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; .........
..............
..............
..............
..............
I added contact form to my blog
ReplyDeleteHey. Just to say tank you for your lib, it works perfect , I really appreciate it
ReplyDeleteThanks again:D
Octavio.
hello
ReplyDeletecan u share with us source code of quricol32.dll?
kind regards
Ersan YAKIT
Application Developer
The source code is included in the archive in C++ folder
ReplyDeleteThe new release of Quricol is available. Download: http://users.telenet.be/ws36637/download/quricol.zip
ReplyDeleteVery well done - works like a charm!!
ReplyDeleteUnfortunately 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
thank you Serhiy Perevoznyk
ReplyDeleteErsan YAKIT
Application Developer
Hi there!
ReplyDeleteI'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
Hello,
ReplyDeleteI 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.
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.
ReplyDeleteDownload: http://users.telenet.be/ws36637/download/quricol.zip
Hi
ReplyDeleteI 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..
Hi, I use delphi xe2.
ReplyDeleteAnd work with quricol32.dll
Please tell me how to use function GetHBitmap.
If text more than 7065 characters, function return nil.
Have same problem as Arun Joseph P.
ReplyDeleteExternal exception C06D007E.
On Create Bitmap File or Just BitMap.
Delphi 2010
Windows Xp,7 x32/x64
This code means that your application can't load quricol.dll
ReplyDelete1. You forgot to copy quricol.dll to your application folder
2. You copied the wrong version (x64 in place of x32) of the dll.
NET Code Generator for C ++ DLL
ReplyDeleteHi,
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
Hello and thank you for this QR-Code-Thingy. ;)
ReplyDeleteI 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
hi Im trying to use quricol on linux. What should I do with widows.h?
ReplyDeleteDo you have some *.so versions?
Quricol is a pure Windows library, but you can uselibqrencode http://fukuchi.org/works/qrencode/index.html.en for your purposes
ReplyDeleteTanks!!!
ReplyDeleteI 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.
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
ReplyDeleteHello Serhiy,
ReplyDeleteThanks 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.
I use delphi 2010
ReplyDeleteWhen you generated the bitmap image using TQRCode.GetBitmapImage assign the resulted bitmap to your Timage.Picture.Bitmap property.
ReplyDeleteImage1.Picture.Bitmap := generatedBitmap;
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:
ReplyDeleteTQRCode.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.
I figured it out I changed my calls to:
ReplyDeleteTQRCode.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 :-)
This comment has been removed by the author.
ReplyDeleteHi;
ReplyDeleteHow 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.
@Gökhan
ReplyDeleteHi,
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.