目录:zxing->encoding->encodinghandler类 中修改 createqrcode方法
private static final int black = 0xff000000; private static final int white = 0xffffffff; public static bitmap createqrcode(string str,int widthandheight) throws writerexception { string contentstoencode = str; if (contentstoencode == null) { return null; } map<encodehinttype, object> hints = new enummap<>(encodehinttype.class); //hints.put(encodehinttype.character_set, encoding); hints.put(encodehinttype.margin, 0); /* default = 4 */ multiformatwriter writer = new multiformatwriter(); bitmatrix result; try { result = writer.encode(contentstoencode, barcodeformat.qr_code , widthandheight, widthandheight, hints); } catch (exception e) { // unsupported format e.printstacktrace(); return null; } int width = result.getwidth(); int height = result.getheight(); int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = result.get(x, y) ? black : color.white; } } bitmap bitmap = bitmap.createbitmap(width, height, bitmap.config.argb_8888); bitmap.setpixels(pixels, 0, width, 0, 0, width, height); return bitmap; }
如对本文有疑问, 点击进行留言回复!!
LongClick原理、上下文菜单原理、EditText长按弹窗原理、WebView长按弹窗自定义、修复WebView全选重复bug ———————————————— 版权声明:本文为CSDN博主「
JobScheduler 实现 特定时间,特定条件(系统空闲,电池电量,磁盘空间 ……)下执行任务
温习Android基础知识——《第一行代码(第三版)》读书笔记 Chapter 10 Service
网友评论