public static Bitmap createQRCode(String str, int size) throws WriterException {
Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
BitMatrix matrix = new MultiFormatWriter().encode(str, BarcodeFormat.QR_CODE, size, size);
int width = matrix.getWidth();
int height = matrix.getHeight();
int[] pixels = new int[width * height];
for(int x = 0; x < width; x ++){
for(int y = 0; y < height; y ++){
if(matrix.get(x, y)){
pixels[y * width + x] = BLACK;
}
}
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
}
EncodingHandler.java 文件源码
java
阅读 55
收藏 0
点赞 0
评论 0
项目:tvConnect_android
作者:
评论列表
文章目录