1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| //绘制二维码 public Bitmap QrCode(String s) throws Exception{ //二维码QR_CODE BarcodeFormat fomt=BarcodeFormat.QR_CODE; //编码转换 String a=new String(s.getBytes("utf-8"),"ISO-8859-1"); BitMatrix matrix=new MultiFormatWriter().encode(a, fomt, width, height); int width=matrix.getWidth(); int height=matrix.getHeight(); int[] pixel=new int[width*height]; for(int i=0;i<height;i++){ for(int j=0;j<width;j++){ if(matrix.get(j,i)) pixel[i*width+j]=0xff000000; } } Bitmap bmap=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888); bmap.setPixels(pixel, 0, width, 0, 0, width, height); return bmap; } //绘制条形码 public Bitmap BarCode(String ss) throws Exception{ //条形码CODE_128 BarcodeFormat fomt=BarcodeFormat.CODE_128; BitMatrix matrix=new MultiFormatWriter().encode(ss, fomt, width, height); int width=matrix.getWidth(); int height=matrix.getHeight(); int[] pixel=new int[width*height]; for(int i=0;i<height;i++){ for(int j=0;j<width;j++){ if(matrix.get(j,i)) pixel[i*width+j]=0xff000000; } } Bitmap bmapp=Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888); bmapp.setPixels(pixel, 0, width, 0, 0, width, height); return bmapp; }
|