Liberty BASIC Community Forum
« QR Codes »

Welcome Guest. Please Login or Register.
Mar 24th, 2017, 4:57pm


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: QR Codes  (Read 1065 times)
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5215
xx Re: QR Codes
« Reply #15 on: Aug 29th, 2016, 09:45am »

I agree, we have managed barcodes in the past. I will try and spend some time on it.

When I looked the last time the encryption choices seemed daunting but it should be possible to get a single format QR code drawn.
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1137
xx Re: QR Codes
« Reply #16 on: Aug 29th, 2016, 4:36pm »

My reply was to a new poster coming new to a five year old thread, not to your original post!

It's obviously POSSIBLE to create QR codes of one or more type from their definition. I'd question WHY to do this. It comes down to the answer of the mountaineer to 'Why do you climb mountains?' which was 'Because they are there.'
When I have 'spare time' I've been known to rise to such challenges. But the practical side of my brain says 'Change to Python. Import the relevant library and import the needed functionality'.

I'd be more interested in creating a new type of code, not bar or QR, and then attempting to implement it, with the necessary error correction. And writing a decoder which implements a pattern recognition, orientates it and decodes reliably. A major effort and no chance of it taking off commercially. But addictive fun, like crosswords....!
And then, I seem to remember making an 8-photocell reader and creating my own paper-tape code/decode software on an 1802 processer in about 1978... Plus ca change.
User IP Logged

marklew1956
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 9
xx Re: QR Codes
« Reply #17 on: Aug 30th, 2016, 4:18pm »

Thanks for the help with the QR code software. I've gotten myself in a bit of a deadline and haven't had sufficient time to research and write the code myself. Now, another question. From the last example, how can I get the resulting window so I can actually print it? That's my ultimate use is to enter information from a tsv database file and have a program generate the barcodes, add the corresponding name and print out the results on a 5 x 8 inch card!
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5215
xx Re: QR Codes
« Reply #18 on: Aug 31st, 2016, 03:50am »

To print the drawing you simply issue the graphicbox print [size] command

When you wish to print draw everything to the graphicbox, the QR image and the text, then issue a single flush command. Then print with #main.g "print 300"

The size parameter will determine how big your image is on the printed page. The graphicbox is 300 so print 300 will spread the whole image across the printed page.Experiment with the size parameter on your card stock and printer.
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5215
xx Re: QR Codes
« Reply #19 on: Aug 31st, 2016, 04:38am »

Back to creating QR codes. Having looked again the range of options is daunting. I don't think it would be practical to build a complete encoding solution that met all standards.

It might be possible to pick out one format and produce a 64 character QR code that can be read by any scanner but is that useful?

If it is an inhouse solution a bar code is simpler. If it is a web address solution then what format (data) is going to be useful?


http://www.thonky.com/qr-code-tutorial/introduction
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1137
xx Re: QR Codes
« Reply #20 on: Aug 31st, 2016, 3:32pm »

The following code prints two images of the selected QR code on a sheet. Easily modified to print a grid of different ones, or positioned to suit label-paper.

NB 1 The scaling is not intuitive.
NB 2 The bounding box for the printed area is made visible. ( my choice)
I wasted a lot of ink getting pages that were black everywhere but the QR part. In such cases it helps to print to pdf until you sort it out! Since I work under Linux I always wonder if it is a Wine bug.... There's definitely something funny. If I use 'print 16000' instead of 'print 8000' the bounding box scales but not the QR codes, whose size I can't change!! I don't have time at present to investigate what's going on. But as it stands you do get your printout.

LB does not give you a printer-select, so you have to make the chosen printer the default.
Code:
    nomainwin

    WindowWidth  = 471
    WindowHeight = 407

    graphicbox #main.g,  5,  6, 456, 366

    open "QR print" for window_nf as #main

'In an LB quirk, you need to be sure there's a bounding box defining possible graphic area
#main.g, "down ; color black ; place 0 0 ; box 8000 7000"

    #main.g "flush"
    #main.g "font Ubuntu 24"

    #main   "trapclose [quit.main]"

    open "gdiplus.dll" for dll as #gdip

    toEncode$   ="marklew1956"
    http$       ="http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=" +toEncode$ +"&chld=H|0"
    result      = DownloadToFile( http$, "QR.png")

    timer 2000, [on0]
    wait
  [on0]
    timer 0

    if result <> 0 then print "Error downloading image.": end

    file$ ="QR.png"

    hBmp    =LoadImgFromFile( file$)
    if hBmp <>0 then
        loadbmp "pic", hBmp
        #main.g     "drawbmp pic  52 52"
        #main.g     "drawbmp pic 372 52"
        unloadbmp "pic"
        calldll #gdi32, "DeleteObject", hBmp as ulong, ret as ulong

        #main.g     "flush ; print 8000"
' The size argument takes the pixels you have drawn and spreads them across the full printed width.
' Our image is 356 pixels wide- but 8000 pixels would be needed to fill the width of the printed page.
    else
        notice "Could not load the image file!"
    end if

    wait


[quit.main]
    close #gdip
    close #main
    end

function wchar$( string$)
    for i = 1 to len( string$)
        wchar$  =wchar$ +mid$( string$, i, 1) +chr$( 0)
    next i

    wchar$  =wchar$ +chr$( 0) +chr$( 0)
end function

function LoadImgFromFile( file$)
    struct dword, a as ulong
    gdistart$   =chr$( 1)

    for i = 1 to 15
        gdistart$   =gdistart$ +chr$( 0)
    next i

    calldll #gdip, "GdiplusStartup", dword as struct, gdistart$ as ptr, status as ulong

    token   =dword.a.struct

    if status <>0 then
        LoadImgFromFile   =0
    else
        wFileLoc$   =wchar$(file$)
        calldll #gdip, "GdipCreateBitmapFromFile", _
        wFileLoc$ as ptr, dword as struct, status as ulong
        hPic        =dword.a.struct

        if status <>0 then
            LoadImgFromFile =0
        else
            calldll #gdip, "GdipCreateHBITMAPFromBitmap", _
            hPic as ulong, dword as struct, 0 as ulong, status as ulong
            hBmp    =dword.a.struct

            if status <>0 then
                LoadImgFromFile =0
            else
                LoadImgFromFile =hBmp
            end if

            calldll #gdip, "GdipDisposeImage", hPic as ulong, ret as ulong
        end if

        calldll #gdip, "GdiplusShutdown", token as ulong, ret as ulong
    end if
end function

Function DownloadToFile( urlfile$, localfile$)
    open "URLmon" for dll as #url
    calldll #url, "URLDownloadToFileA",_
    0 as long,_         'null
    urlfile$ as ptr,_   'url to download
    localfile$ as ptr,_ 'save file name
    0 as long,_         'reserved, must be 0
    0 as long,_         'callback address, can be 0
    DownloadToFile as ulong  '0=success
    close #url
end function
 
User IP Logged

Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5215
xx Re: QR Codes
« Reply #21 on: Sep 1st, 2016, 06:48am »

I changed John's example a little. I put in a down command, I did away with the large box which is only necessary if you are using scroll bars to see the image.

I changed the graphicbox size to 800x500 and then used size 800 as the printing parameter. This spreads the whole graphicbox across the width of the printed page.

It produces quite a large QR code, you can make it look a lot smaller by increasing both the size of the graphicbox and the printing size parameter. An 8000x5000 graphicbox and a print size parameter of 8000 would make the QR code one tenth of its current size. Play you can't break it.

Code:
    nomainwin

    WindowWidth  = 900
    WindowHeight = 600

    graphicbox #main.g,  10,  10, 800, 500

    open "QR print" for window_nf as #main

    #main.g "down"
    #main   "trapclose [quit.main]"

    open "gdiplus.dll" for dll as #gdip

    toEncode$   ="marklew1956"
    http$       ="http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=" +toEncode$ +"&chld=H|0"
    result      = DownloadToFile( http$, "QR.png")

    timer 2000, [on0]
    wait
  [on0]
    timer 0

    if result <> 0 then print "Error downloading image.": end

    file$ ="QR.png"

    hBmp    =LoadImgFromFile( file$)
    if hBmp <>0 then
        loadbmp "pic", hBmp
        #main.g     "drawbmp pic  222 72" '222,72 = 356 pixel image in middle of 800x500 graphicbox

        unloadbmp "pic"
        calldll #gdi32, "DeleteObject", hBmp as ulong, ret as ulong

        #main.g     "flush ; print 800"
    ' The size argument takes the pixels you have drawn and spreads them across the full printed width.
    ' Our image is 356 pixels wide the graphicbox is 800 pixels wide so to spread the graphicbox
    ' across the width of the printed page requires a size of 800.
    ' If you have your printer set to use 8x5 cards then the graphicbox image will fill the card
    ' and the QR code in my example will be in the middle of the card quite large.
    ' You can adjust the size of the printed QR code by changing the size parameter. If you make
    ' the size parameter bigger and the graphicbox bigger the QR code will shrink in size on the printed page.
    ' So a size of 8000 and a graphicbox 8000 wide will make the QR code much smaller and you can place it
    ' anywhere in the graphicbox
    else
        notice "Could not load the image file!"
    end if

    wait


[quit.main]
    close #gdip
    close #main
    end

function wchar$( string$)
    for i = 1 to len( string$)
        wchar$  =wchar$ +mid$( string$, i, 1) +chr$( 0)
    next i

    wchar$  =wchar$ +chr$( 0) +chr$( 0)
end function

function LoadImgFromFile( file$)
    struct dword, a as ulong
    gdistart$   =chr$( 1)

    for i = 1 to 15
        gdistart$   =gdistart$ +chr$( 0)
    next i

    calldll #gdip, "GdiplusStartup", dword as struct, gdistart$ as ptr, status as ulong

    token   =dword.a.struct

    if status <>0 then
        LoadImgFromFile   =0
    else
        wFileLoc$   =wchar$(file$)
        calldll #gdip, "GdipCreateBitmapFromFile", _
        wFileLoc$ as ptr, dword as struct, status as ulong
        hPic        =dword.a.struct

        if status <>0 then
            LoadImgFromFile =0
        else
            calldll #gdip, "GdipCreateHBITMAPFromBitmap", _
            hPic as ulong, dword as struct, 0 as ulong, status as ulong
            hBmp    =dword.a.struct

            if status <>0 then
                LoadImgFromFile =0
            else
                LoadImgFromFile =hBmp
            end if

            calldll #gdip, "GdipDisposeImage", hPic as ulong, ret as ulong
        end if

        calldll #gdip, "GdiplusShutdown", token as ulong, ret as ulong
    end if
end function

Function DownloadToFile( urlfile$, localfile$)
    open "URLmon" for dll as #url
    calldll #url, "URLDownloadToFileA",_
    0 as long,_         'null
    urlfile$ as ptr,_   'url to download
    localfile$ as ptr,_ 'save file name
    0 as long,_         'reserved, must be 0
    0 as long,_         'callback address, can be 0
    DownloadToFile as ulong  '0=success
    close #url
end function


 
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1137
xx Re: QR Codes
« Reply #22 on: Sep 1st, 2016, 07:55am »

...and just to point out that you can download at smaller size in the first place, eg
Code:
http$       ="http://chart.apis.google.com/chart?cht=qr&chs=100x100&chl=" +toEncode$ +"&chld=H|0" 
User IP Logged

CarlGundel
Administrator
ImageImageImageImageImage


member is offline

Avatar

author of Liberty BASIC


Homepage PM


Posts: 2730
xx Re: QR Codes
« Reply #23 on: Sep 2nd, 2016, 07:56am »

If the idea is to implement QR codes as a fun project, you might get your toes wet by implementing 3of9 barcodes first (for fun). It's a lot easier. I did it myself years ago.

-Carl
User IP Logged

author of Liberty BASIC
http://www.libertybasic.com
CryptoMan
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 301
xx Re: QR Codes
« Reply #24 on: Sep 13th, 2016, 03:37am »

I also did barcode but that's so much simpler.

The question is QR codes.

Why do it in pure LB?

Well, I want it to work in offline mode. You can not always have Internet connection. Or, website can be unavailabe or can stop this service.

After all, many other things can be without LB but here we are trying to show anything can be doable with LB.

I know that making a QR generator is not easy but should be doable. It's a challenge.

Like Rosetta Code: Write a function in LB to generate QR code.
User IP Logged

.....
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5215
xx Re: QR Codes
« Reply #25 on: Sep 13th, 2016, 1:54pm »

Andy did another barcode and I posted a compressed barcode so there are several examples to search out. But a QR code would be good.

Currently stalled on the encryption and error checking code.

Might take me a while to work through that so any contributions welcome.
User IP Logged

CryptoMan
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 301
xx Re: QR Codes
« Reply #26 on: Sep 30th, 2016, 3:02pm »

There are some good tutorials on Internet for QR now and I think it is doable if there is sufficient time.

There is a LUA source code and maybe a LUA>>>LB translator can be written and this code can be converted to LB.

I will do it when I can find some time.
User IP Logged

.....
KaylaB
New Member
Image


member is offline

Avatar




PM

Gender: Female
Posts: 1
xx Re: QR Codes
« Reply #27 on: Nov 14th, 2016, 12:08am »

This might be of use
http://fukuchi.org/works/qrencode/
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls