ZXing加速QR编码 [英] Accelerate QR-Encoding with ZXing

查看:70
本文介绍了ZXing加速QR编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在一个Android项目中使用大量QR代码,对此 zxing 是我的首选库.

I'm currently working with a lot of QR-Codes in an Android project, for which zxing is my preferred library.

要实际显示生成的QR码,将使用编码中的信息创建位图.

To actually display the generated QR-Code a Bitmap is created with the information from the encoding.

QRCodeWriter writer = new QRCodeWriter();
BitMatrix matrix = writer.encode(message, BarcodeFormat.QR_CODE, px, px);

Bitmap bitmap = Bitmap.createBitmap(px, px, Bitmap.Config.RGB_565);
for (int x = 0; x < px; x++) {
    for (int y = 0; y < px; y++) {
        bitmap.setPixel(x, y, matrix.get(x,y) ? Color.BLACK : Color.WHITE);
    }
}

这很好,但是非常慢.即使是很小的位图,整个过程也要花费几秒钟.

This works just fine, however it's terribly slow. Even for rather small Bitmaps it takes several seconds for the entire process.

是否有一种方法可以智能地加快此过程(例如并行化)甚至更好的库?

Is there a way to intelligently speed up this procedure (e.g. parallelisation) or even a better library?

提前谢谢.

推荐答案

从这个意义上讲,我遇到了同样的问题,我通过关注这个人设法大大加快了我的二维码加载速度:

I have had the same problem in this sense, I managed to accelerate my qr code loading significantly by following this guy:

https://www.youtube.com/watch?v=-vWHbCr_OWM

希望这将帮助那些为此而苦苦挣扎并遇到此问题的人.

Hope this will help anyone who struggles with this and comes across this thread.

实际上,也许我可以为您省去麻烦:

Actually perhaps i can save you the trouble:

在gradle中:

compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'

在代码中:

        String myStringToEncode = "Something";
        MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
        BitMatrix bitMatrix = multiFormatWriter.encode(myStringToEncode, BarcodeFormat.QR_CODE,200,200);
        BarcodeEncoder barcodeEncoder = new BarcodeEncoder();
        Bitmap bitmpap = barcodeEncoder.createBitmap(bitMatrix);

最后,我通过其变量调用ImageView控件

And then finally I call my ImageView control by its variable

       imgQR.setImageBitmap(bitmpap);

这篇关于ZXing加速QR编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆