It is currently Sat Dec 14, 2019 10:16 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Create QRCode (2D-Barcode)
PostPosted: Fri Oct 21, 2011 7:09 am 
Offline
Addict
Addict
User avatar

Joined: Wed Apr 30, 2003 8:15 am
Posts: 991
Location: Germany
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

_________________
"Daddy, I'll run faster, then it is not so far..."


Last edited by dige on Wed Oct 03, 2012 3:17 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Fri Oct 21, 2011 1:17 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4548
Location: Lyon - France
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

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Sat Oct 22, 2011 6:39 am 
Offline
Addict
Addict
User avatar

Joined: Fri Sep 21, 2007 5:52 am
Posts: 3426
Location: New Zealand
nice thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Sat Oct 22, 2011 9:35 am 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1482
Is there a way to do it without relying on external files like qrcodelib.lib and qrcodelib.dll?

_________________
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Sat Oct 22, 2011 12:38 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5755
Location: Berlin - Germany
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:

_________________
PureBasic 5.71 | SpiderBasic 2.21 | Windows 10 Pro (x64) | Linux Mint 19.2 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Sun Oct 23, 2011 12:06 am 
Offline
Addict
Addict
User avatar

Joined: Mon May 14, 2007 2:13 am
Posts: 979
Location: Darling River
Good one dige. :)

_________________
PureBasic Rocks! Even More! And More!
PureBasic 5, Now We're Really Rockin!


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Sun Oct 23, 2011 9:08 pm 
Offline
User
User
User avatar

Joined: Wed May 05, 2004 8:21 pm
Posts: 36
Location: An outer spiral arm of the Milky Way
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"


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Tue Jul 30, 2013 5:46 am 
Offline
User
User
User avatar

Joined: Fri Mar 04, 2005 7:46 pm
Posts: 73
Location: argentina
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"

_________________
Amd Vishera fx8350 ,16Gbram, Gtx650 ti, 2gb,Win 10pro. 13tbs. 8)


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Wed Jul 31, 2013 3:46 am 
Offline
Addict
Addict
User avatar

Joined: Mon May 14, 2007 2:13 am
Posts: 979
Location: Darling River
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.

_________________
PureBasic Rocks! Even More! And More!
PureBasic 5, Now We're Really Rockin!


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Wed Jul 31, 2013 12:21 pm 
Offline
Addict
Addict

Joined: Fri Apr 25, 2003 11:10 pm
Posts: 1216
you can use polib to make the lib
polib qrcodelib.dll /machine:ix86 /out:qrcodelib.lib


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Fri Aug 02, 2013 4:33 am 
Offline
Addict
Addict
User avatar

Joined: Mon May 14, 2007 2:13 am
Posts: 979
Location: Darling River
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. :)

_________________
PureBasic Rocks! Even More! And More!
PureBasic 5, Now We're Really Rockin!


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Sat Aug 03, 2013 3:59 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Oct 16, 2003 8:30 pm
Posts: 1998
Location: North Florida
Image

5.20 b 8


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Tue Aug 06, 2013 11:41 am 
Offline
Addict
Addict

Joined: Sun Jun 25, 2006 7:28 pm
Posts: 1383
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Tue Aug 06, 2013 2:53 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Oct 16, 2003 8:30 pm
Posts: 1998
Location: North Florida
Image

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

- np


Top
 Profile  
Reply with quote  
 Post subject: Re: Create QRCode (2D-Barcode)
PostPosted: Tue Aug 06, 2013 3:29 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 1324
Location: (Embarrassed to say country)
did you create the lib as indicated before your 1st post?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye