Code Monkey home page Code Monkey logo

Comments (5)

ITxiaoguang avatar ITxiaoguang commented on August 31, 2024

你的问题不是很理解.
想要图片中的二维码图片的话,这个框架是不支持的. 但是可以这样,通过扫图片得到单个或多个二维码String,再通过二维码转Bitmap工具把单个或多个二维码String转成Bitmap图片.可是转换后的Bitmap图片和原图中的二维码可能不相同.
String转二维码Bitmap工具:https://blog.csdn.net/zzr1114969538/article/details/76461022

from mlkitscanner.

zghnx avatar zghnx commented on August 31, 2024

我的意思,一张图片中有二维码,我想把这个二维分离出来另存为一张图片

from mlkitscanner.

ITxiaoguang avatar ITxiaoguang commented on August 31, 2024

可从刚刚提交里面看到实现,或者下面实现:
在ScanResultPointView中 的

        for (int j = 0; j < resultPoint.size(); j++) {
            Barcode barcode = resultPoint.get(j);
            Rect boundingBox = barcode.getBoundingBox(); 

后面加上这些代码:

           // 扫描得到二维码的 左边线  上边线  右边线  下边线
            // 这样便可从图片中扣出这个二维码

            int left = boundingBox.left;
            int top = boundingBox.top;
            int right = boundingBox.right;
            int bottom = boundingBox.bottom;

            Bitmap bitmap = Bitmap.createBitmap(barcodeBitmap, left, top, right - left, bottom - top);

            try {
                // 需打开存储权限
                String path = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + fl_result_point_root.getContext().getPackageName() + "/cache/";
                File dir = new File(path);
                if (!dir.exists()) {
                    dir.mkdirs();
                }
                path += System.currentTimeMillis() + "qrcode.png";
                FileOutputStream fout = new FileOutputStream(path);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fout);
                Log.i("ScanResultPointView", "qrcode picture path: " + path);
            } catch (Exception e) {
                e.printStackTrace();
            }

from mlkitscanner.

zghnx avatar zghnx commented on August 31, 2024

可从刚刚提交里面看到实现,或者下面实现: 在ScanResultPointView中 的

        for (int j = 0; j < resultPoint.size(); j++) {
            Barcode barcode = resultPoint.get(j);
            Rect boundingBox = barcode.getBoundingBox(); 

后面加上这些代码:

           // 扫描得到二维码的 左边线  上边线  右边线  下边线
            // 这样便可从图片中扣出这个二维码

            int left = boundingBox.left;
            int top = boundingBox.top;
            int right = boundingBox.right;
            int bottom = boundingBox.bottom;

            Bitmap bitmap = Bitmap.createBitmap(barcodeBitmap, left, top, right - left, bottom - top);

            try {
                // 需打开存储权限
                String path = Environment.getExternalStorageDirectory().getPath() + "/Android/data/" + fl_result_point_root.getContext().getPackageName() + "/cache/";
                File dir = new File(path);
                if (!dir.exists()) {
                    dir.mkdirs();
                }
                path += System.currentTimeMillis() + "qrcode.png";
                FileOutputStream fout = new FileOutputStream(path);
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, fout);
                Log.i("ScanResultPointView", "qrcode picture path: " + path);
            } catch (Exception e) {
                e.printStackTrace();
            }

可以了。感谢!

from mlkitscanner.

zghnx avatar zghnx commented on August 31, 2024

public void onPreview(final byte[] nv21, Camera camera) {

        YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, camera.getParameters().getPreviewSize().width, camera.getParameters().getPreviewSize().height, null);
        ByteArrayOutputStream stream = new ByteArrayOutputStream(nv21.length);
        yuvImage.compressToJpeg(new Rect(0, 0, yuvImage.getWidth(), yuvImage.getHeight()), 90, stream);

        Bitmap bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());


        InputImage inputImage = InputImage.fromBitmap(bitmap, 0);
        //InputImage inputImage = InputImage.fromMediaImage(imageProxy.getImage(), imageProxy.getImageInfo().getRotationDegrees());

// final Bitmap finalBitmap = bitmap;

        barcodeScanner.process(inputImage)
                .addOnSuccessListener(new OnSuccessListener<List<Barcode>>() {
                    @Override
                    public void onSuccess(@NonNull List<Barcode> barcodes) {
                        if (barcodes.size() == 0) {
                            return;
                        }

                        for (Barcode barcode : barcodes) {
                            String value = barcode.getRawValue();
                            Log.e("======", "value:" + value);
                        }

                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.e("======", "onFailure---:" + e.toString());
                    }
                });

}
不知道为什么解析不了。

from mlkitscanner.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.