- URI uri = new URI("http", null, "chart.apis.google.com", -1, "/chart",
- "cht=qr&chs=" + mPixelResolution + "x" + mPixelResolution + "&chl=" + mContents, null);
- HttpUriRequest get = new HttpGet(uri);
- client = AndroidHttpClient.newInstance(mUserAgent);
- HttpResponse response = client.execute(get);
- HttpEntity entity = response.getEntity();
- Bitmap image = BitmapFactory.decodeStream(entity.getContent());
- if (image != null) {
- Message message = Message.obtain(mHandler, R.id.encode_succeeded);
- message.obj = image;
- message.sendToTarget();
- } else {
- Log.e(TAG, "Could not decode png from the network");
- Message message = Message.obtain(mHandler, R.id.encode_failed);
- message.sendToTarget();
+ ByteMatrix result = new MultiFormatWriter().encode(mContents, BarcodeFormat.QR_CODE,
+ mPixelResolution, mPixelResolution);
+ int width = result.width();
+ int height = result.height();
+ byte[][] array = result.getArray();
+ int[] pixels = new int[width * height];
+ for (int y = 0; y < height; y++) {
+ for (int x = 0; x < width; x++) {
+ int grey = array[y][x] & 0xff;
+ pixels[y * width + x] = (0xff << 24) | (grey << 16) | (grey << 8) | grey;
+ }