B4J Question QRCode generator: Save png file as real bw (1 Bit)

KMatle

Expert
Licensed User
Longtime User
I'm generating QCodes with Erel's QRCode generator. Later I print these on a POS printer (via file). Here the images are distorted. In Xnview I've seen that the png files have up to 57 colours (though all used colours are black and white). After conversion (via XnView)to 1 Bit (pure bw) the POS printer prints like a charm.

QRView.SetBitmap(QR.Create(QRString)) Dim im As Image = QRView.Snapshot Dim Out As OutputStream = File.OpenOutput(File.DirApp, "qr.png",False) im.WriteToStream(Out) Out.Close:
QRView.SetBitmap(QR.Create(QRString))
Dim im As Image  = QRView.Snapshot
Dim Out As OutputStream = File.OpenOutput(File.DirApp, "qr.png",False)
im.WriteToStream(Out)
Out.Close

Q: How do I save the png file as a "real" bw file?
 

Pendrush

Well-Known Member
Licensed User
Longtime User
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
My one-cent

The several colors that you see (grayscale levels) are due to expanding the B4XBitmap returned by QR.create(QRString) to fit into QRView, which has different dimensions than the original bitmap. Anti-aliasing does the rest.

If, instead, you save the same Image returned by QR.Create, it will only have white and black pixels (event if it is saved in 32-bit format)

(Using Erel's example)
B4X:
' Don't do this
    Dim im As Image  = ImageView1.Snapshot    '<-- Here you are taking the snapshot of the visualization of the bitmap, which is anti-aliased.
    Dim Out As OutputStream = File.OpenOutput(File.DirApp, "qr.png",False)
    im.WriteToStream(Out)
    Out.Close
Result (anti-aliased, grayscale transitions)

qr.png


B4X:
'Do that
    Dim imOK As Image  = qr.Create("QR with B4X!!!")
    Dim OutOK As OutputStream = File.OpenOutput(File.DirApp, "qrOK.png",False)
    imOK.WriteToStream(OutOK)
    OutOK.Close
Result (not anti-aliased since it is the originally generated bitmap)

qrOK.png
 
Upvote 0
Top