title: Generating QR code for Android with High error correction
body: <p>I'm currently generating a QR code in my Android app but the customer complained that we need to generate codes with <a href="https://en.wikipedia.org/wiki/QR_code#Error_correction" rel="nofollow">High error correction</a>.</p>
  
  <p>The code I'm currently using is the following, but the problem is that I don't know how to actually generate the QR image with the certain error connection:</p>
  
  <pre><code>private Bitmap encodeAsBitmap(String contents, BarcodeFormat format, int img_width, int img_height) throws WriterException {
          String contentsToEncode = contents;
          if (contentsToEncode == null) {
              return null;
          }
          Map&lt;EncodeHintType, Object&gt; hints = null;
          String encoding = guessAppropriateEncoding(contentsToEncode);
          if (encoding != null) {
              hints = new EnumMap&lt;EncodeHintType, Object&gt;(EncodeHintType.class);
              hints.put(EncodeHintType.CHARACTER_SET, encoding);
          }
          MultiFormatWriter writer = new MultiFormatWriter();
          BitMatrix result;
          try {
              result = writer.encode(contentsToEncode, format, img_width, img_height, hints);
          } catch (IllegalArgumentException iae) {
              // Unsupported format
              return null;
          }
          int width = result.getWidth();
          int height = result.getHeight();
          int[] pixels = new int[width * height];
          for (int y = 0; y &lt; height; y++) {
              int offset = y * width;
              for (int x = 0; x &lt; width; x++) {
                  pixels[offset + x] = result.get(x, y) ? BLACK : WHITE;
              }
          }
  
          Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
          bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
          return bitmap;
      }
  </code></pre>
  
  <p>Thanks a lot for the help in advance!</p>