content: package com.google.zxing.util;
  
  import android.graphics.Bitmap;
  import android.graphics.Color;
  
  import com.google.zxing.BarcodeFormat;
  import com.google.zxing.EncodeHintType;
  import com.google.zxing.MultiFormatWriter;
  import com.google.zxing.WriterException;
  import com.google.zxing.common.BitMatrix;
  import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
  
  import java.util.HashMap;
  import java.util.Map;
  
  public class QrCodeGenerator {
  
      public static Bitmap getQrCodeImage(String data, int width, int height) {
          if (data == null || data.length() == 0) {
              return null;
          }
          Map<EncodeHintType, Object> hintsMap = new HashMap<>(3);
          hintsMap.put(EncodeHintType.CHARACTER_SET, "utf-8");
          hintsMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
          hintsMap.put(EncodeHintType.MARGIN, 0);
          try {
              BitMatrix bitMatrix = new MultiFormatWriter().encode(data, BarcodeFormat.QR_CODE, width, height, hintsMap);
              Bitmap bitmap = bitMatrix2Bitmap(bitMatrix);
              return bitmap;
          } catch (WriterException e) {
              e.printStackTrace();
          }
          return null;
      }
  
      private static Bitmap bitMatrix2Bitmap(BitMatrix matrix) {
          int w = matrix.getWidth();
          int h = matrix.getHeight();
          int[] rawData = new int[w * h];
          for (int i = 0; i < w; i++) {
              for (int j = 0; j < h; j++) {
                  int color = Color.WHITE;
                  if (matrix.get(i, j)) {
                      color = Color.BLACK;
                  }
                  rawData[i + (j * w)] = color;
              }
          }
          Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
          bitmap.setPixels(rawData, 0, w, 0, 0, w, h);
          return bitmap;
      }
  
  }
  