Liberty BASIC Community Forum
« QR Codes »

Welcome Guest. Please Login or Register.
Jun 25th, 2017, 12:18am


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


« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: QR Codes  (Read 1166 times)
CryptoMan
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 302
xx QR Codes
« Thread started on: Nov 13th, 2011, 03:49am »

Can somebody generate QR Codes with LB ?

http://en.wikipedia.org/wiki/QR_code
User IP Logged

.....
stefanhes
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 723
xx Re: QR Codes
« Reply #1 on: Nov 13th, 2011, 06:09am »

Everyone who can draw a filled square on the screen can.
QR-code = a lot of squares. After that use


#gb "print"
dump


User IP Logged

http://www.soundofanimals.com
http://sincosin.com
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Re: QR Codes
« Reply #2 on: Nov 13th, 2011, 08:41am »

A neat way is to ask Google to do it for you- the following code is derived from Alyce's examples of scraping web content. Change the destination of the saved file if it gives grief in W7- I nearly always use ramdisk R:\ for such files..
I can't vouch for the result tho.!
Change the text you want- I used my web moniker of 'tenochtitlanuk'.
User Image
Code:
'Download an image from given URL to file on disk.

'LB NL 141?? & Alyce's Restaurant

http$ ="http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=tenochtitlanuk&chld=H|0"

nomainwin

result = DownloadToFile( http$, "QR.png")
timer 2000, [on]
wait
[on]
timer 0
if result <> 0 then
    print "Error downloading image."
else
    run "mspaint.exe " + chr$(34) +"QR.png" + chr$(34)
    print "Done"
end if

end

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: 1154
xx Re: QR Codes
« Reply #3 on: Nov 17th, 2011, 4:47pm »

Further comment- there are also on-line services to decode QR codes in a similar way- or you can download free exes that will run on your machine.
User IP Logged

CS
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 60
xx Re: QR Codes
« Reply #4 on: Nov 19th, 2011, 12:23pm »

Hello,

I use this site for my QR code needs.

http://www.qrstuff.com/

Not sure exactly on the conventions for the codes.
User IP Logged

I read more than I write
jaba
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 325
xx Re: QR Codes
« Reply #5 on: Nov 19th, 2011, 4:17pm »

I had never even heard of QR codes until I read this post. Now, everywhere I go I see them. Interesting...
User IP Logged

If I didn't first try it and get it wrong, I may never have figured out how to get it right.
CryptoMan
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 302
xx Re: QR Codes
« Reply #6 on: Nov 23rd, 2011, 3:08pm »

Thanks for all the replies.

I know all of those Internet based services.

I would like to know if anybody implemented this in pure Liberty Basic by obtaining the ISO standard for QR codes and implement the algorithm of how to draw all of the squares as described in the standard.

Probably there is some C or C++ open source which can be converted into Liberty Basic. The standard is quite complicated. I like to try it one day if I can find some time.

If anyone wants to see the standard and give it try can send me a message with his/her email.

I think it is a good intellectual challenge. I tend to believe anything is possible with LB.
User IP Logged

.....
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5312
xx Re: QR Codes
« Reply #7 on: Nov 24th, 2011, 01:39am »

I had a look but hesitated because there seems to be such a variety of styles and encryption methods.

If there is one particular standard that you think would be right for Liberty why not publish the link.
User IP Logged

CryptoMan
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 302
xx Re: QR Codes
« Reply #8 on: Nov 24th, 2011, 11:54am »

INTERNATIONAL STANDARD ISO/IEC 18004

Information technology Automatic identification and data capture techniques QR Code 2005 bar code symbology specification



ISO/IEC
18004
Reference number
ISO/IEC 18004:2006(E)

Second edition
2006-09-01
User IP Logged

.....
marklew1956
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 9
xx Re: QR Codes
« Reply #9 on: Aug 25th, 2016, 09:10am »

Using the example above, how hard would it be to save the PNG file to disk? I'm not a power user and it seems that I each project I tackle has a few new challenges I have to overcome... this time it's the opening a url and saving the resulting png graphic to disk!
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Re: QR Codes
« Reply #10 on: Aug 25th, 2016, 12:58pm »

Easy! The original code saved it anyway! ( Look in the directory where you saved the LB code.) I've changed the code to make it more obvious where your code goes, and removed the line that opened it in Paint. Works OK for me under Linux...
Code:
'Download an image from given URL to file on disk.

'LB NL 141?? & Alyce's Restaurant

toEncode$ ="marklew1956"

http$ ="http://chart.apis.google.com/chart?cht=qr&chs=300x300&chl=" +toEncode$ +"&chld=H|0"

nomainwin

result = DownloadToFile( http$, "QR.png")
timer 2000, [on]
wait
[on]
timer 0
if result <> 0 then
    print "Error downloading image."
else
    print "Done, Saved as "; "QR.png"
end if

end

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

marklew1956
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 9
xx Re: QR Codes
« Reply #11 on: Aug 27th, 2016, 1:07pm »

Thanks for the help! What I'm actually trying to do is get a text line and the qrcode on the same graphic window. What will be the simplest way to open the saved image and place it on a graphic window?
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Re: QR Codes
« Reply #12 on: Aug 27th, 2016, 4:20pm »

LB uses bmp image files. So it can't display a png directly. BUT...
To display a png you have several LB options- and I don't know how much experience you have.
One way is GDIplus. See GDIplus article
My way of choice on Linux ( or in the past MS Windows machines) is to install the free ImageMagick, which adds commands accessible from LB to size, load and alter in every conceivable way any image of any format. You'll find some examples on my website.
EDIT
ImageMagick

If this takes you out of your comfort zone I can try to create an example.
« Last Edit: Aug 27th, 2016, 4:25pm by tenochtitlanuk » User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Re: QR Codes
« Reply #13 on: Aug 28th, 2016, 4:31pm »

Here's an example using the GDI+ code from LB encyclopedia. You'll need to change the font name if you you don't use LB under Linux/Wine.
User Image
Code:
    nomainwin

    WindowWidth  = 400
    WindowHeight = 500

    graphicbox #main.g,  50,  50, 302, 352

    open "Picture load" for window_nf as #main

    #main.g "down; fill 30 30 80; color red; backcolor 30 30 80  ; 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 0 0; flush"
        unloadbmp "pic"    'Because LB doesnt delete it for us
        calldll #gdi32, "DeleteObject", hBmp as ulong, ret as ulong
        #main.g     "up; goto 60 340; down"
        #main.g     "\"; toEncode$
    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
 


When I tried the ( should be easier) calling of ImageMagick it failed on my Linux machine and I don't have a MS Windows machine here to try it.
Does anyone see why
Code:
    IM$         ="identify " +chr$( 34) +"/media/john/Stick2G/QR.png" +chr$( 34) +" > " +chr$( 34) +"/media/john/Stick2G/identify.txt" +chr$( 34)
    '   NB  identify "/media/john/Stick2G/QR.png" > "/media/john/Stick2G/identify.txt" works from terminal....
    run "cmd.exe /C "; chr$( 34); IM$; chr$( 34), HIDE
 

The command works from the Terminal, and other commands like
Code:
"dir > dir.txt" 
work happily...
It's been some time since I used the LB/ImageMagick combination.
User IP Logged

CryptoMan
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 302
xx Re: QR Codes
« Reply #14 on: Aug 29th, 2016, 09:18am »

All of these are palliative solutions. What I meant when I originally asked was a source code which will generate QR code from first principles in offline mode by implementing the required algorithm and using LB graphics primitives.

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