zxing生成二维码
来源:互联网 发布:林非比的淘宝店铺 编辑:程序博客网 时间:2024/06/06 03:11
zxing生成二维码
public class QrCodeUtil { public static Bitmap creaQrCode(String content, int qrWidth, int qrHeight) { return createQrCode(content, "utf-8", Color.BLACK, qrWidth, qrHeight, ErrorCorrectionLevel.H, null); } public static Bitmap createQrCode(String content, String characterSet, int qrColor, int qrWidth, int qrHeight , ErrorCorrectionLevel ecl, Bitmap logo) { if (content == null) { return null; } if (characterSet == null) { characterSet = "utf-8"; } if (ecl == null) { ecl = ErrorCorrectionLevel.H; } Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, characterSet); hints.put(EncodeHintType.ERROR_CORRECTION, ecl); hints.put(EncodeHintType.MARGIN, 0); try { BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, qrWidth, qrHeight, hints); int[] piexs = new int[qrWidth * qrHeight]; for (int y = 0; y < qrHeight; y++) { for (int x = 0; x < qrWidth; x++) { if (bitMatrix.get(x, y)) { piexs[y * qrWidth + x] = qrColor; } else { piexs[y * qrWidth] = 0xffffffff; } } } Bitmap bitmap = Bitmap.createBitmap(qrWidth, qrHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawBitmap(piexs, 0, qrWidth, 0, 0, qrWidth, qrHeight, true, null); if (logo != null) { int logoHeight = qrHeight / 5; int logoWidth = qrWidth / 5; canvas.drawBitmap(genThumbnails(logo, logoWidth, logoHeight), (qrWidth - logoWidth) / 2.0f, (qrHeight - logoHeight) / 2.0f, null); } return bitmap; } catch (WriterException e) { e.printStackTrace(); } return null; } private static Bitmap genThumbnails(Bitmap logo, int logoWidth, int logoHeight) { if (logo == null || logoHeight < 0 || logoWidth < 0) { throw new IllegalArgumentException(); } Bitmap bitmap = Bitmap.createBitmap(logoWidth, logoHeight, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); canvas.drawColor(Color.WHITE); canvas.drawBitmap(Bitmap.createScaledBitmap(logo, logoWidth - 10, logoHeight - 10, false), 5, 5, null); return bitmap; }}
0 0
- 利用ZXing生成二维码
- ZXing二维码生成
- ZXing生成二维码
- 采用zxing生成二维码
- 利用Zxing生成二维码
- 使用zxing生成二维码
- 使用ZXing生成二维码
- 使用zxing生成二维码
- zxing生成二维码
- google ZXing 生成二维码
- 使用zxing生成二维码
- zxing生成二维码
- **利用Zxing生成二维码
- Android zxing生成二维码
- ZXing生成二维码
- 使用zxing生成二维码
- Zxing生成二维码
- Google ZXing生成二维码
- GUI编程 窗体事件
- dubbo+zk实现demo
- 4.1.数组指针和指针数组和二重指针
- weka连接sqlserver2005
- java复习(-)基本类型
- zxing生成二维码
- DP 练习 uva103 Stacking Boxs
- MQ实现分布式事务
- 聚类算法汇总
- ImageLoader的简单使用详情
- 自定义圆形图片
- java的API/Object
- 汽水3换1问题编程
- androlyze.py使用方法【三】