展会信息港展会大全

如何通过ZXING将字符串转化为二维码Bitmap
来源:互联网   发布日期:2016-01-14 11:31:25   浏览:1828次  

导读:dependencies { compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar' compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar' compile 'com.journeyapps:zxing-android-integration:2.0.1@aar' compile 'com.google.zxing:core:3.0.1' } public...

dependencies {

compile 'com.journeyapps:zxing-android-embedded:2.0.1@aar'

compile 'com.journeyapps:zxing-android-legacy:2.0.1@aar'

compile 'com.journeyapps:zxing-android-integration:2.0.1@aar'

compile 'com.google.zxing:core:3.0.1'

}

public static Bitmap generateQRCodeFromString(String content) throws WriterException {

Map hints = new HashMap();

MultiFormatWriter multiFormatWriter = new MultiFormatWriter();

hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");

BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, QR_WIDTH, QR_HEIGHT, hints);

int[] pixels = new int[QR_WIDTH * QR_HEIGHT];

for (int y = 0; y < QR_HEIGHT; y++) {

for (int x = 0; x < QR_WIDTH; x++) {

if (bitMatrix.get(x, y)) {

pixels[y * QR_WIDTH + x] = 0xff000000;

} else {

pixels[y * QR_WIDTH + x] = 0xffffffff;

}

}

}

Bitmap bitmap = Bitmap.createBitmap(QR_WIDTH, QR_HEIGHT,

Bitmap.Config.ARGB_8888);

bitmap.setPixels(pixels, 0, QR_WIDTH, 0, 0, QR_WIDTH, QR_HEIGHT);

return bitmap;

}

赞助本站

人工智能实验室

相关热词: android开发 android教程

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港