2

I would like to use ZXing to generate QR code and show it on screen, however I require that the QR code is shown over a specific background [image]. Is it possible with ZXing?

Thanks

EDIT: It would also be great to be able to change status bar title from plain text [I'm using TYPE_TEXT] to something else.

Krystian
  • 3,193
  • 2
  • 33
  • 71

3 Answers3

1

Just create the barcode image using the library and display it in your very own activity. You can style that anyway you like.

Community
  • 1
  • 1
323go
  • 14,143
  • 6
  • 33
  • 41
  • I don't think it's possible to do by just using the android-integration library. When calling `startActivityForResult` there's no result returned. I'm trying to use it the 'proper' way - with intents. If I was to include zxing as lib with my app I would simply modify the existing layout. – Krystian Nov 07 '12 at 22:33
  • What's the hesitation in including the library? The license is not encumbered, the size is very reasonable (especially once you reduce it to the functionality you need), and you are no longer dependent on another app/package to be installed. – 323go Nov 08 '12 at 06:18
  • 1
    When using intent I may concentrate on my app and leave everything QR related to Sean Owne and other devs ;) This way, whenever they update something I don't need to worry about releasing new version of my app. Especially because I use barcode scanning in my app as well. – Krystian Nov 08 '12 at 08:06
  • 1
    @323go the problem is that most people 'embedding' the library are copying and pasting. In the context of an app, and Android, this apparently harmless type of reuse causes problems: Intent interference, spurious support requests, consumer confusion, trademark problems. I don't think that is likely to be an issue here. But Krystian et al. see the problem and are rightly thinking carefully about reus.e – Sean Owen Nov 08 '12 at 12:17
1

This is example of how to create transparent QR code with ZXING library:

        QRCodeWriter qrCodeWriter = new QRCodeWriter();
        // create output image
        BufferedImage image = new BufferedImage(382, 382, BufferedImage.TYPE_INT_ARGB);
        // create bit matrix
        BitMatrix bitMatrix = new MultiFormatWriter().encode(
                qrCodeString,
                BarcodeFormat.QR_CODE, 382, 382);
        // set pixels of output image based of bit matrix (black or translucent)
        for (int i = 0; i < 382; i++) {
            for (int j = 0; j < 382; j++) {
                image.setRGB(i,j, bitMatrix.get(i,j) ? Color.BLACK.getRGB() : Color.TRANSLUCENT);
            }
        }
        // write output image as png
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        ImageIO.write(image, "PNG", outputStream);
Majo
  • 96
  • 1
  • 4
0

There is not a way. Typically the barcode needs a quiet zone of white around it so it is not something you generally want to do. If you really need to this is a case where you write your own layout and embed the same kind of code that makes the display.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
  • The quiet zone is specified as only four times the block-size. It's really not a big deal. – 323go Nov 08 '12 at 06:16
  • I'm doing that in an app I wrote using Appcelerator, and it works fine [with the quiet zone]. So it seems the only way to do it is as 323go suggested. – Krystian Nov 08 '12 at 08:07
  • @Sean Owen i have scanned image after scannig image i m moving to new activity now i want to display image of previously screen scanned barcode ? – Erum Jan 26 '15 at 07:50