0

"I want to display the image on screen." After scanning the QR code I need to show that as image in my application how to go about it.


I have tried this but not getting output

   BarcodeFormat barcodeFormat = BarcodeFormat.QR_CODE;
        int width0 = 500;
        int height0 = 500;

        int colorBack = 0xFF000000;
        int colorFront = 0xFFFFFFFF;

        QRCodeWriter writer = new QRCodeWriter();
        try
        {
            Hashtable<EncodeHintType, Object> hint = new Hashtable<EncodeHintType,Object>(2);
            hint.put(EncodeHintType.CHARACTER_SET, "UTF-8");
            ByteMatrix bitMatrix = writer.encode(fName, barcodeFormat, width0, height0, hint);
            int width = bitMatrix.getWidth();
            int height = bitMatrix.getHeight();
            int[] pixels = new int[width * height];
            for (int y = 0; y < height; y++)
            {
                int offset = y * width;
                for (int x = 0; x < width; x++)
                {

                   // if (bitMatrix.get(x, y))
                        pixels[offset + x] = colorBack;
                    //else
                        //pixels[offset + x] = colorFront;
                }
            }

            Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
            bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
            ImageView imageview = (ImageView)findViewById(R.id.imageView1);
            imageview.setImageBitmap(bitmap);
        } catch (WriterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Rick
  • 33
  • 7
  • [this](http://stackoverflow.com/q/14321095/1777090) should help. – MysticMagicϡ Sep 04 '14 at 10:29
  • do you mean u first scan the qr code as well as take a picture of that qr code and show it in your android view ? – Sagar Pilkhwal Sep 04 '14 at 10:30
  • [Zxing](https://code.google.com/p/zxing/) is an excellent library for QR-codes. You will find what you need there, including an android sample project. you can use it to decode the qr code and later encode it and display it in your android view. – Sagar Pilkhwal Sep 04 '14 at 10:34
  • Zxing is the way to go, will do what you ask.. BUT I'm not entirely sure what you want. You want to display an image of the QR code, OR an image that is linked / embedded **within** the QR code? – RossC Sep 04 '14 at 10:41
  • thanx @SagarPilkhwal for reply. I wanted to display the scanned image into my app. – Rick Sep 04 '14 at 12:54
  • you can take a picture using camera intent – Sagar Pilkhwal Sep 04 '14 at 12:56
  • thanx @Dhruti for reply, But i alredy done the QR scanner , but i wanted to display the image as well. – Rick Sep 04 '14 at 12:57
  • @SagarPilkhwal Yeah i have done that but i am not able to access display the QR code image – Rick Sep 04 '14 at 13:07

0 Answers0