Android Question Need to save created QRcode to image file

microbox

Active Member
Licensed User
Longtime User
Hi everyone, I have a snippet code that will create a qr code. But now I need to save it as image file. Can anyone kindly point the way how to do it?
The following is what I'm using so far.
B4X:
Sub qrCreator(vfname As String)
    Dim qr As QRGenerator
    qr.Initialize(ImageView1.Width)
    ImageView1.SetBitmap(qr.Create(vfname))
    Log("created!")
    
    ' I can not make the code below run properly
    
    'Dim imgPreview As ImageView
    'imgPreview.Initialize("")
    'Dim b As Bitmap
    'b.Initialize(File.DirRootExternal , vfname & ".jpg")
    'b = imgPreview.Bitmap
    'Dim out As OutputStream
    'out = File.OpenOutput(File.DirRootExternal & "/" & AppName, vfname & ".jpg", False)
    'b.WriteToStream(out, 100, "JPEG")
    'out.Close
End sub
 

microbox

Active Member
Licensed User
Longtime User
Thank you for the reply @Mahares. I change the code and now works fine.
B4X:
Dim img As Bitmap
    Dim qr As QRGenerator
    qr.Initialize(ImageView1.Width)
    Log("created!")
    
    ImageView1.BringToFront
    ImageView1.Visible = True
    img = qr.Create(vfname)

    ImageView1.SetBitmap(img)
    '-----------------------------
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal & "/" & AppName, vfname & ".jpg", False)
    Log("it pass this line")
    img.WriteToStream(out, 100, "JPEG")
    out.Close
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…