Creating QR Code 2D bar codes

This forum is for posting of useful information
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Creating QR Code 2D bar codes

#1 Post by rdonnay »

This is a sample program showing how to create a QR Code BMP file.

This sample uses the MW6Tech ActiveX control.

See https://www.mw6tech.com/qrcode/qrcode.html

This is not a free control.

The file, MW6QRCode.ZIP, contains the install program for the demo version of the ActiveX Control.

The barcode contains my name and address info.

Code: Select all

#INCLUDE "dcdialog.CH"

#Pragma Library("ascom10.lib")

FUNCTION Main()

LOCAL i, oCode, cString := ''
LOCAL nActualRows := 0, nActualCols := 0
LOCAL nActualWidth := 0, nActualHeight := 0
LOCAL nExtraWidth := 0, nExtraHeight := 0

oCode := CreateObject("MW6QRCode.QRCode")

TEXT INTO cString WRAP
Roger J. Donnay
1486 S. Loggers Pond Place
Apt. # 11
Boise, ID 83706
208-867-6091
ENDTEXT

oCode:Data := cString

// Get the actual rows and columns of QRCode barcode
oCode:GetActualRC(@nActualRows, @nActualCols)

// Get the actual QRCode barcode width and height
// The size value is based on computer screen resolution
oCode:GetActualSize( .T.,0, @nActualWidth, @nActualHeight )

IF .t.
  oCode:SetSize(nActualWidth + nExtraWidth, nActualHeight + nExtraHeight)
ELSE
  oCode:SetSize(nActualHeight + nExtraWidth, nActualWidth + nExtraHeight)
ENDIF

// Create a BMP file in the current folder
oCode:SaveAsBMP(DC_Path(AppName(.t.)) + "\MW6Demo.bmp")

RETURN nil

MW6Demo.jpg
MW6Demo.jpg (10.76 KiB) Viewed 33007 times
The eXpress train is coming - and it has more cars.

User avatar
sdenjupol148
Posts: 151
Joined: Thu Jan 28, 2010 10:27 am
Location: NYC

Re: Creating QR Code 2D bar codes

#2 Post by sdenjupol148 »

Awesome Roger,
Now I have to figure out how I can use it. :think:

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: Creating QR Code 2D bar codes

#3 Post by unixkd »

Hi Roger

I intend to explore the QR Code 2D bar codes. But would like to now a low price barcode reader supported by this activex. We are planning to print barcodes on plastic id cards for one of our applications.

Thanks.

Joe

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Creating QR Code 2D bar codes

#4 Post by rdonnay »

Code: Select all

would like to now a low price barcode reader
Are you asking for a reader that reads plastic cards?

Bobby and I recently implemented a drivers license scanner into his application.
The hardware is DuplexScan 1210. About $200 on Amazon.com.
The eXpress train is coming - and it has more cars.

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: Creating QR Code 2D bar codes

#5 Post by Zdeno Bielik »

Hi Roger,

I finally started play with sample code, but it looks that doesn’t generate correct results
just see attached picture/code and generated images/files
if you scan each qrcode and compare it with source code/text, it is not same
Where may be problem?

Zdeno
Attachments
qr.zip
(39.54 KiB) Downloaded 1053 times

User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Creating QR Code 2D bar codes

#6 Post by rdonnay »

I don't have an answer for you.
I have no experience with this other than the small test program I wrote.
The eXpress train is coming - and it has more cars.

Piotr D
Posts: 129
Joined: Mon Jul 28, 2014 1:26 am
Location: Poznań, Poland

Re: Creating QR Code 2D bar codes

#7 Post by Piotr D »

Zdenko
I use MW6QRCode four years. Below is, how I create these. The text, which is "QR-printed" was UTF-8 encoded.
But Alaska have problem with "transport" polish national fonts into :data slot. Author of these library make speciall for
me new method :setCharAt(char, position) which place char by char text into :data slot. With these method QR code was
created with good translation of polish national characters. Probably, you have the same problem.

Piotr

FUNCTION CreateQR_BMP(cTekst)
* Create an temporary BMP with QR code
*************************************************************

Local oControl,cFileTmp:='QR'+STRZERO(RandomInt(1,65000),5)+STRZERO(RandomInt(1,65000),5)+'.BMP',nX:=0,nY:=0,i,nVersion

oControl := XbpActiveXControl():new()
oControl:CLSID := "{3BB56637-651D-4D1D-AFA4-C0506F57EAF8}"
bOldError := ErrorBlock( {|e| Break(e)} )
BEGIN SEQUENCE
oControl:create(,, {0,0},{80,80})
RECOVER USING oError
IF oError:subCode == 6500
DC_MsgBox(,,{'UWAGA! Blad tworzenia kontrolki ActiveX.',;
'Prosze sprawdz czy zainstalowano na',;
'komputerze kontrolki MW6 QRCode.'})
QUIT
ENDIF
RETURN('')
END SEQUENCE
ErrorBlock( bOldError )

* tekst must be in UTF-8
cTekst:=cOemToUTF8(cTekst)

* rodzaj obramowania
oControl:BorderStyle:=2

* this is only for creation of :data buffer
*
oControl:Data:=cTekst
*
* Alaska send wrong "outside" text in UTF-8 (some ASCII below 128)
* In this case I don't use :data
* instead I use special method, which place into :data buffer every char by value
*
FOR i:=1 TO LEN(cTekst)
oControl:setCharAt(ASC(SUBS(cTekst,i,1)),i-1)
NEXT

* test for a size of QR code
oControl:GetActualSize(.T.,0,@nX,@nY)
oControl:destroy()
* second time the same but for correct size
oControl:create(,, {0,0},{nX,nY})
oControl:BorderStyle:=2
oControl:Data:=cTekst
FOR i:=1 TO LEN(cTekst)
oControl:setCharAt(ASC(SUBS(cTekst,i,1)),i-1)
NEXT
* save the BMP with QR in temporary file

oControl:SaveAsBMP(cFileTmp)
oControl:destroy()
i:=1
* zaczekaj, az plik powstanie
DO WHILE !FExists(cFileTmp) .AND. i<5
i:=i+1
sleep(20)
ENDDO
RETURN(cFileTMP)

Zdeno Bielik
Posts: 147
Joined: Thu Jan 28, 2010 9:24 am
Location: Nitra, Slovakia
Contact:

Re: Creating QR Code 2D bar codes

#8 Post by Zdeno Bielik »

Hi Piotr,

it looks that demo version has no SetCharAt method, anyway, many thanks for sample.
If I can kindly ask you, please, can you create QR code with text bellow
and post it here – thank you.

Zdeno BIELIK
123456
tel: 12-3456
ľščŤÁÓ
čp 12.04.2017 - 32.18,-
Hello

Zdeno


oError:args :
-> VALTYPE:C VALUE:setCharAt
-> VALTYPE:N VALUE:97
-> VALTYPE:N VALUE:0
oError:canDefault : .T.
oError:canRetry : .F.
oError:canSubstitute: .T.
oError:cargo : NIL
oError:description : Neznßmy nßzov.
Object has no method with this name
oError:filename : NIL
oError:genCode : NIL
oError:operation : setCharAt
oError:osCode : -2147352570
oError:severity : 2
oError:subCode : 6500
oError:subSystem : Automation
oError:thread : 1
oError:tries : NIL
Attachments
qr-test2.jpg
qr-test2.jpg (11.23 KiB) Viewed 25436 times

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: Creating QR Code 2D bar codes

#9 Post by Auge_Ohr »

it does not work to copy / paste your Country special Sign from Browser to my German Environment.
try to copy Chinese Sign from Browser into your Notepad and save it ... :lol:

i have same Problem with my "QR DLL" and German "Umlaute"
Umlaute.jpg
Umlaute.jpg (44.84 KiB) Viewed 25428 times
if you scan it you will see missing "Umlaute" before @ 0123456789 :naughty:

it seem me that most Solution use ANSI and not OEM to generate QR Code
i know there is a Chinese Version for Chinese sign -> QR Code ... but i don't know how it works :?:
greetings by OHR
Jimmy

Piotr D
Posts: 129
Joined: Mon Jul 28, 2014 1:26 am
Location: Poznań, Poland

Re: Creating QR Code 2D bar codes

#10 Post by Piotr D »

Zdenko,
send me your e-mail and I send you this library.
When I test QR-code, I find another ActiveX - Stroke Scribe. This have more possibility, have no problem
with national language (text is set as OEM, encoding to UTF-8 make these library) and is cheaper.
Below is sample.

Piotr

FUNCTION PD_CreateQR_BMP_Stroke(cTekst)
* cTekst i OEM-tekst to print
*************************************************************
Local oControl,cFileTmp:='QR'+STR(Seconds()*100,7,0)+'.BMP',nX:=0,nY:=0

oControl := XbpActiveXControl():new()
oControl:CLSID := "{7E42B8C5-73BE-4806-8904-FF4080A6960C}"
bOldError := ErrorBlock( {|e| Break(e)} )
BEGIN SEQUENCE
oControl:create(,, {0,0},{80,80})
RECOVER USING oError
IF oError:subCode == 6500
DC_MsgBox(,,{'UWAGA! BˆĄd tworzenia kontrolki ActiveX.',;
'Prosz© sprawd« czy zainstalowano na',;
'komputerze kontrolki Stroke Scribe.'})
QUIT
ENDIF
RETURN('')
END SEQUENCE
ErrorBlock( bOldError )

* select printing QR
oControl:Alphabet:=25
* text to print
oControl:Text:=cTekst
* set UTF-8 encoding.
oControl:UTF8:=.T.

* size of bitmap
nX:=oControl:BitmapH
* now can I create
oControl:destroy()
oControl:create(,, {0,0},{nx,nx})
oControl:Alphabet:=25
oControl:Text:=cTekst
oControl:UTF8:=.T.

oControl:CopyToClipboard()
oControl:SavePicture(cFileTmp,0,nX,nX,0)
oControl:destroy()
RETURN(cFileTMP)

Post Reply