Get a qrcode scanned image in onActivityResult usi

2020-03-25 06:08发布

I am scanning the qrcode successfully and displaying the result url into the textview following. etxt_qrcode.setText(intent.getStringExtra("SCAN_RESULT")); Now i want to display the scanned image into imageview.I don't know exactly what i want to do.Is zxing return anything related to image to display imageview or tell me the process to display the result scanned image into imageview.please give me a needful help i am struggling from past two days on this.thanks.

标签: android zxing
3条回答
家丑人穷心不美
2楼-- · 2020-03-25 06:30

This can be easily achieved by the following: first before start intent set : setBarcodeImageEnabled(true); and after that you will get image path in OnActivityResult like following: String path=intent.getStringExtra("SCAN_RESULT_IMAGE_PATH");

Thanks

查看更多
狗以群分
3楼-- · 2020-03-25 06:31

There may be no direct way to get the image from the intent extras but there is a workaround that may help, after you get the decoded string you can convert it to image again. here is a code to do so,

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
            IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
            if (scanResult != null) {
                generateQRCode(scanResult.getContents());
            }

        }
    }

public void generateQRCode(String data){
        com.google.zxing.Writer wr = new MultiFormatWriter();
        try {
            int width = 350;
            int height = 350;
            BitMatrix bm = wr.encode(data, BarcodeFormat.QR_CODE, width, height);
            mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {

                    mBitmap.setPixel(i, j, bm.get(i, j) ? Color.BLACK : Color.WHITE);
                }
            }
        } catch (WriterException e) {
            e.printStackTrace();
        }
        if (mBitmap != null) {

            img.setImageBitmap(mBitmap);
        }
    }
查看更多
乱世女痞
4楼-- · 2020-03-25 06:32

There's not a way to do it. The image is not returned. The problem is that the image can be quite large to parcel. But with downsampling and compression, probably not a big deal. I'd entertain a patch if you want to work on it. http://code.google.com/p/zxing

查看更多
登录 后发表回答