PureBasic Forum
http://forums.purebasic.com/english/

Create QRCode (2D-Barcode)
http://forums.purebasic.com/english/viewtopic.php?f=12&t=47938
Page 1 of 2

Author:  dige [ Fri Oct 21, 2011 7:09 am ]
Post subject:  Create QRCode (2D-Barcode)

Image
Link to http://www.purebasic.com

Code:
; by Dige 10/2011
; http://www.purebasic.fr/english/viewtopic.php?f=12&t=47938
; Create 2D Barcodes (QRCode) based on qrencode-win32
; Requires: qrcodelib.lib, qrcodelib.dll
; http://code.google.com/p/qrencode-win32/downloads/list

Structure QRCode
  Version.l
  Width.l
  pSymbolData.l
EndStructure

Enumeration
  #QR_ECLEVEL_L = 0 ; lowest
  #QR_ECLEVEL_M
  #QR_ECLEVEL_Q
  #QR_ECLEVEL_H     ; highest
EndEnumeration

ImportC "..\Lib\qrcodelib.lib"
  QRcode_encodeString8bit(Text.p-ascii, Version.l, QRecLevel.l) As "_QRcode_encodeString8bit"
  QRcode_free(*Qrcode.QRCode) As "_QRcode_free"
EndImport

Procedure CreateQRCode (content.s, ImgID = #PB_Any, EC_Level = #QR_ECLEVEL_L, Size=4 )
  Protected *Qrcode.QRCode, QRImg
 
  *Qrcode = QRcode_encodeString8bit(content, 0, EC_Level)
 
  With *Qrcode
    If *Qrcode = 0 Or \Width = 0
      ProcedureReturn #Null
    Else
      *mem = \pSymbolData
      w    = \Width
    EndIf
  EndWith
 
  QRImg  = CreateImage(ImgID, w, w)
 
  If QRImg
    If ImgID = #PB_Any
      ImgID = QRImg
    EndIf
  EndIf
 
  If StartDrawing(ImageOutput(ImgID))
      ; White Background
      Box (0, 0, ImageWidth(ImgID), ImageHeight(ImgID), #White) 
     
      ; Draw Black Dots
      For y = 0 To w - 1
        For x = 0 To w - 1
          b = PeekB(*mem) & $FF
          If b & 1
            Plot( x, y, #Black)
          EndIf
          *mem + 1
        Next
      Next
     
    StopDrawing()
   
    w * Size
    ResizeImage( ImgID, w, w, #PB_Image_Raw)
  EndIf
 
  QRcode_free(*Qrcode)
 
  ProcedureReturn ImgID
EndProcedure

; Example, how to use it:
CreateImage(0, 200, 200)

OpenWindow(#Null, 0, 0, 450, 400, "2D Barcode Creator", #WS_OVERLAPPEDWINDOW|#PB_Window_ScreenCentered )
TextGadget(#PB_Any, 10, 4, 50, 16, "Text" )
StringGadget(0, 10, 20, 200, 20, "Feel the Pure Power!" )

TextGadget(#PB_Any, 10, 44, 50, 16, "EC_Level" )
TrackBarGadget(1, 10, 60, 100, 20, #QR_ECLEVEL_L, #QR_ECLEVEL_H, #PB_TrackBar_Ticks)

TextGadget(#PB_Any, 110, 44, 50, 16, "Size" )
TrackBarGadget(2, 110, 60, 100, 20, 1, 10, #PB_TrackBar_Ticks)

ImageGadget (3, 10, 90, 430, 550, ImageID(0), #PB_Image_Border)

Repeat
 
  Event = WaitWindowEvent()
 
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case 0, 1, 2
        ImgID = CreateQRCode(GetGadgetText(0), #Null, GetGadgetState(1), GetGadgetState(2))
        If IsImage(ImgID)
          SetGadgetState(3, ImageID(ImgID))
        EndIf
    EndSelect
  EndIf

Until Event = #PB_Event_CloseWindow

Author:  Kwai chang caine [ Fri Oct 21, 2011 1:17 pm ]
Post subject:  Re: Create QRCode (2D-Barcode)

Thanks a lot DIGE for sharing 8)
That's works fine

Perhaps a day you can create the scanner, like for normal Barcode :wink:
http://www.purebasic.fr/german/viewtopi ... 74#p288174

Good day

Author:  idle [ Sat Oct 22, 2011 6:39 am ]
Post subject:  Re: Create QRCode (2D-Barcode)

nice thanks

Author:  MachineCode [ Sat Oct 22, 2011 9:35 am ]
Post subject:  Re: Create QRCode (2D-Barcode)

Is there a way to do it without relying on external files like qrcodelib.lib and qrcodelib.dll?

Author:  ts-soft [ Sat Oct 22, 2011 12:38 pm ]
Post subject:  Re: Create QRCode (2D-Barcode)

MachineCode wrote:
Is there a way to do it without relying on external files like qrcodelib.lib and qrcodelib.dll?

Translate the c-source to pb or write your own code :mrgreen:

Author:  electrochrisso [ Sun Oct 23, 2011 12:06 am ]
Post subject:  Re: Create QRCode (2D-Barcode)

Good one dige. :)

Author:  fiver [ Sun Oct 23, 2011 9:08 pm ]
Post subject:  Re: Create QRCode (2D-Barcode)

Thanks for sharing! This will be really useful, these seem to be everywhere nowadays.
I managed to compile static libraries for linux and osx, see link below, on osx the images seem blurred which may be something to do with the 2D drawing lib in RC2 - the osx qrencode console version produced pngs that were fine.
I tried to build the static lib for windows but while it compiled ok, polink complained about missing references to strdup. This is a known problem though it seems, with mingw not properly exporting some functions and will likely be addressed in the next release of qrencode.

Link for the linux and osx libs:

http://goo.gl/xlJ9m

On linux change the import statement in Dige's code to:

ImportC "libqrencode.a"
QRcode_encodeString8bit(Text.p-ascii, Version.l, QRecLevel.l) As "QRcode_encodeString8bit"
QRcode_free(*Qrcode.QRCode) As "QRcode_free"
EndImport

For osx just change the first line of the import to:

ImportC "libqrencode.a"

Author:  zefiro_flashparty [ Tue Jul 30, 2013 5:46 am ]
Post subject:  Re: Create QRCode (2D-Barcode)

https://docs.google.com/leaf?id=0B_EW83 ... ist&num=50

https://docs.google.com/leaf?id=0B_EW83tN7qz-NjUzNGE2OGYtNTA3Ni00MTZkLWI1YzctNmVhMzk1MTQzZmI3&sort=name&layout=list&num=50
download QrcodeXtra.7z

unpack
qrcodelib.dll
qrcodelib.lib

and copy to
"C:\Program Files\PureBasic\Compilers"

Author:  electrochrisso [ Wed Jul 31, 2013 3:46 am ]
Post subject:  Re: Create QRCode (2D-Barcode)

zefiro_flashparty wrote:
https://docs.google.com/leaf?id=0B_EW83tN7qz-NjUzNGE2OGYtNTA3Ni00MTZkLWI1YzctNmVhMzk1MTQzZmI3&sort=name&layout=list&num=50

https://docs.google.com/leaf?id=0B_EW83tN7qz-NjUzNGE2OGYtNTA3Ni00MTZkLWI1YzctNmVhMzk1MTQzZmI3&sort=name&layout=list&num=50
download QrcodeXtra.7z

unpack
qrcodelib.dll
qrcodelib.lib

and copy to
"C:\Program Files\PureBasic\Compilers"

Where is the qrcodelib.lib :?:
I can not see it in the download.

Author:  jack [ Wed Jul 31, 2013 12:21 pm ]
Post subject:  Re: Create QRCode (2D-Barcode)

you can use polib to make the lib
polib qrcodelib.dll /machine:ix86 /out:qrcodelib.lib

Author:  electrochrisso [ Fri Aug 02, 2013 4:33 am ]
Post subject:  Re: Create QRCode (2D-Barcode)

jack wrote:
you can use polib to make the lib
polib qrcodelib.dll /machine:ix86 /out:qrcodelib.lib

Too easy, thanks for the info Jack. :)

Author:  NoahPhense [ Sat Aug 03, 2013 3:59 pm ]
Post subject:  Re: Create QRCode (2D-Barcode)

Image

5.20 b 8

Author:  applePi [ Tue Aug 06, 2013 11:41 am ]
Post subject:  Re: Create QRCode (2D-Barcode)

thanks, very beautiful, after adding SaveImage(0,"pic.bmp") at the last line ,i have pasted the text in my post here to the text box, then uploading the png version of the bmp to http://www.onlinebarcodereader.com/ , it display exactly this same post. impressive. but the text should be continuous ie no new line.
Image

Author:  NoahPhense [ Tue Aug 06, 2013 2:53 pm ]
Post subject:  Re: Create QRCode (2D-Barcode)

Image

What am I doing wrong that I cannot get this to work with 5.20 b8?

- np

Author:  jassing [ Tue Aug 06, 2013 3:29 pm ]
Post subject:  Re: Create QRCode (2D-Barcode)

did you create the lib as indicated before your 1st post?

Page 1 of 2 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/