问题
I'm currently working with a lot of QR-Codes in an Android project, for which zxing is my preferred library.
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?
Thanks in advance.
回答1:
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:
in gradle:
compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
compile 'com.google.zxing:core:3.2.1'
In code:
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);
And then finally I call my ImageView control by its variable
imgQR.setImageBitmap(bitmpap);
来源:https://stackoverflow.com/questions/39352172/accelerate-qr-encoding-with-zxing