Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

QRCode using PB

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • QRCode using PB

    It's not a complete QRCode library, but it covers it enough to be very useful. Encodes Numeric, Alpha Numeric, Byte.

    You can display into a graphic control/windows
    Code:
     sText = "otpauth://totp/MyCompany?secret=NAR5XTDD3EQU22YU"
    
    
     '// Create the QRCode matrix
     '// (DataToMakeIntoQR, ErrorCorectionLevel, ArrayToPutMatrixIn)  returns version used for supplied data
     Version = CreateQRCode (sText, 3, aQRMatrix()) ' 1=L 7%, 2=M 15%, 3=Q 25%, 4=H 30%
    
     '//Convert Matrix into device-independent bitmap in a dynamic string and then display it in a control or Graphic Window
      sBuffer = GetQRCodeAsBITSstr (aQRMatrix(), 3, 6)                ' Matrix,  border, Magnification
     lgWidth =  CVL(sBuffer,1)
     lgHeight = CVL(sBuffer,5)
                GRAPHIC WINDOW NEW "Version "+FORMAT$(Version), 10, 10, lgWidth, lgHeight  TO hWinVar
                GRAPHIC ATTACH hWinVar, 0
                GRAPHIC SET BITS sBuffer
                GRAPHIC WAITKEY$
    Save QRCode in format desired
    Code:
     sText = "otpauth://totp/MyCompany?secret=NAR5XTDD3EQU22YU"
    
    '// Create the QRCode matrix
    '// (DataToMakeIntoQR, ErrorCorectionLevel, ArrayToPutMatrixIn) returns version used for supplied data
     Version = CreateQRCode (sText, 3, aQRMatrix()) ' 1=L 7%, 2=M 15%, 3=Q 25%, 4=H 30%
    
    '// Save QRCode as an image filename extention determins format ie: myImage.png myImage.jpg myImage.tif myImage.gif myImage.bmp
        SaveQRCodeAsImage (aQRMatrix(),"myImage.png", 3, 6)   ' Matrix, File Name, border, Magnification


    Print QRCode
    Code:
     sText = "otpauth://totp/MyCompany?secret=NAR5XTDD3EQU22YU"
    
    '// Create the QRCode matrix
    '// (DataToMakeIntoQR, ErrorCorectionLevel, ArrayToPutMatrixIn) returns version used for supplied data
     Version = CreateQRCode (sText, 3, aQRMatrix()) ' 1=L 7%, 2=M 15%, 3=Q 25%, 4=H 30%
    
    '//Convert Matrix into device-independent bitmap in a dynamic string and then Print it
    LOCAL xsize, ysize, hbmp, hbmp2 AS LONG
    sBuffer = GetQRCodeAsBITSstr (aQRMatrix(), 3, 6)    ' Matrix,  border, Magnification
    IF sBuffer <> "" THEN
        xsize = CVL(sBuffer,1)                          ' Get Size of Bar Code
        ysize = CVL(sBuffer,5)
        GRAPHIC BITMAP NEW xsize, ysize TO hbmp         ' Create bitmap 1
        GRAPHIC ATTACH hbmp,0
        GRAPHIC SET BITS sBuffer                         ' Put BITS in it
    
        GRAPHIC BITMAP NEW xsize*2, ysize*2 TO hbmp2    ' Create bitmap double size
        GRAPHIC ATTACH hbmp2,0
        GRAPHIC STRETCH PAGE hBmp, 0                    ' stretch bitmap 1 in it
    
          XPRINT ATTACH CHOOSE
          XPRINT SCALE  (0,0)-(8.5,11)          'scale paper size
          XPRINT
          XPRINT "  Page Scaled at (8.5,11)"
          XPRINT "  BMP1 size   : " + FORMAT$(xsize),FORMAT$(ysize)
          XPRINT "  Scaled size : " + FORMAT$(xsize / XPRINT(PPI.X), 4),FORMAT$(ysize / XPRINT(PPI.Y),4)
          XPRINT "  BMP2 size   : " + FORMAT$(xsize*2),FORMAT$(ysize*2)
          XPRINT "  Scaled size : " + FORMAT$(xsize*2 / XPRINT(PPI.X), 4),FORMAT$(ysize*2 / XPRINT(PPI.Y),4)
          XPRINT SET POS (5, .5)
          XPRINT "Barcode under me"
          XPRINT COPY hbmp, 0 TO (5, 0.7)      'put barcode at 5 in x .7 in
          XPRINT COPY hbmp2, 0 TO (5-((xsize*2/XPRINT(PPI.X)+.1)), ysize/ XPRINT(PPI.Y)+.8)
          XPRINT CLOSE
    
        GRAPHIC ATTACH hbmp,0                          ' Cleanup
        GRAPHIC BITMAP END
        GRAPHIC ATTACH hbmp2,0
        GRAPHIC BITMAP END
      END IF
    Attached Files

  • #2
    Cool! I am going to have to figure out what is going on here!

    WOW! This is amazing!

    Comment


    • #3
      What's New:
      • Substantial Speed improvement.
      • we can now also save as SVG vector graphic image. (used in web, and preferred in publications like big signs and posters)
      I also noticed that the SLL only works in the environment of the compiler used. So if compiled with PBWIN it will not LINK with PBCC programs, and vise versa. (surprising since the same source code compiles and works unaltered with both PBWIN and PBCC respectively.

      New Function Save SVG

      Code:
      ' Save as SVG vector graphic (useful in web, or on big posters) small file for huge images
      ' Matrix, File Name, border, Magnification, background color, dots color
      SaveQRCodeAsSVG (aQRMatrix(),"myImage.svg", 3, 6, %WHITE, %BLACK)

      Included in zip:
      Create QRCode PBCC.bas (test source code for PBCC)
      Create QRCodePBCC SLL.bas (SLL source code for PBCC)
      Create QRCode.bas (test source code for PBWIN)
      Create QRCode SLL.bas (SLL source code for PBWIN)
      QRCode.SLL
      QRCodePBCC.SLL


      (I have no plans to further work on this unless bugs are found)
      Attached Files

      Comment


      • #4
        Originally posted by Rod Macia View Post
        I also noticed that the SLL only works in the environment of the compiler used. So if compiled with PBWIN it will not LINK with PBCC programs, and vise versa.
        That's because of the two lines where you have a "?" command.
        '
        Code:
        ...
          IF (LEN(MsgIn) + nsym) > 255 THEN ? "Message is too long (" + DEC$(LEN(MsgIn) + nsym) + " when max is 255)"    
        ...  
        ? "GdipSaveImageToFile - status code: " & STR$(hStatus)      
        '
        PBCC compiles that as CON.PRINT (Legacy: PRINT). PBWIn compiles it as MSGBOX.

        Since those are compiler specific, the SLL is not "cross-compiler compatible"
        See: https://forum.powerbasic.com/forum/u...565#post814565

        Commenting thos lines or doing the following makes the SLL usable with either compiler, both for creating the SLL and for linking it.
        '
        Code:
        #INCLUDE "Win32API.inc"
        ...
         IF (LEN(MsgIn) + nsym) > 255 THEN messagebox(0, "Message is too long (" + DEC$(LEN(MsgIn) + nsym) + " when max is 255)" ,"",0)
        ...  
               messagebox 0, "GdipSaveImageToFile - status code: " & STR$(hStatus),"",0  
        '

        Comment


        • #5
          I knew about the compiler specific issues, but how the "?" are compiled in PBCC and PBWIN did not cross my mind, So thanks for that Stuart!

          So there we have it Single SLL cross compiler. (when applying changes in post #4).

          Comment

          Working...
          X