Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- String QRcode = "...";
- new generateQrcode(qrcodeImageview).execute(QRcode);
- ...
- private class generateQrcode extends AsyncTask<String, Void, Bitmap> {
- public final static int WIDTH = 400;
- ImageView bmImage;
- public generateQrcode(ImageView bmImage) {
- this.bmImage = bmImage;
- }
- protected Bitmap doInBackground(String... urls) {
- String Value = urls[0];
- com.google.zxing.Writer writer = new QRCodeWriter();
- Bitmap bitmap = null;
- BitMatrix bitMatrix = null;
- try {
- bitMatrix = writer.encode(Value, com.google.zxing.BarcodeFormat.QR_CODE, WIDTH, WIDTH,
- ImmutableMap.of(EncodeHintType.MARGIN, 1));
- bitmap = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
- for (int i = 0; i < 400; i++) {
- for (int j = 0; j < 400; j++) {
- bitmap.setPixel(i, j, bitMatrix.get(i, j) ? Color.BLACK
- : Color.WHITE);
- }
- }
- } catch (WriterException e) {
- e.printStackTrace();
- }
- return bitmap;
- }
- protected void onPostExecute(Bitmap result) {
- bmImage.setImageBitmap(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement