• 利用zxing生成二维码


    使用zxing类库可以很容易生成二维码QRCode,主要代码如下:

     private Bitmap createQRCode(String str,int width,int height)
     {
            Bitmap bmp=null;
            if(str.equals(""))return null;
            try
            {
                 MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
                 Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
                 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
                 hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
                 BitMatrix bitMatrix=null;
                 try 
                 {
                      bitMatrix = multiFormatWriter.encode(str, BarcodeFormat.QR_CODE, width, height,hints);
                 } 
                 catch (WriterException e) 
                 {
                    e.printStackTrace();
                 }
                 
                 int[] pixels = new int[width * height];
                 for (int y = 0; y < height; y++) 
                 {
                     for (int x = 0; x < width; x++) 
                     {
                         if (bitMatrix.get(x, y)) 
                         {
                             pixels[y * width + x] = 0xff000000;
                         } 
                         else 
                         {
                             pixels[y * width + x] = 0xffffffff;
                         }
                     }
                 }
                 bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                 bmp.setPixels(pixels, 0, width, 0, 0, width, height);
               
            }
            catch(Exception e)
            {
                e.printStackTrace();
                bmp=null;
            }
            return bmp;
     }
  • 相关阅读:
    sublime生成html快捷标签布局
    vue.js选项卡动态组件
    textarea内容限制字数
    60s验证等待
    vue.js显示隐藏
    CSS强制性换行
    Ultra Pull To Refresh下拉刷新
    Open经验库网址
    Fresco实例
    解决LinearLayout中控件不能居右对齐
  • 原文地址:https://www.cnblogs.com/rainboy2010/p/4760838.html
Copyright © 2020-2023  润新知