use of com.google.zxing.WriterException in project run-wallet-android by runplay.
the class QR method generateImage.
public static void generateImage(final String text, final ImageView showView, Activity activity) {
if (text.trim().isEmpty()) {
// alert("Ketik dulu data yang ingin dibuat QR Code");
return;
}
// endEditing();
// showLoadingVisible(true);
new Thread(new Runnable() {
@Override
public void run() {
int size = showView.getMeasuredWidth();
if (size > 1) {
// Log.e("QR", "size is set manually");
size = 260;
}
Map<EncodeHintType, Object> hintMap = new EnumMap<>(EncodeHintType.class);
hintMap.put(EncodeHintType.CHARACTER_SET, "UTF-8");
hintMap.put(EncodeHintType.MARGIN, 1);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
try {
BitMatrix byteMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, size, size, hintMap);
int height = byteMatrix.getHeight();
int width = byteMatrix.getWidth();
final Bitmap qrImage = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
qrImage.setPixel(x, y, byteMatrix.get(x, y) ? Color.BLACK : Color.WHITE);
}
}
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
showView.setImageBitmap(qrImage);
// activity.showImage(self.qrImage);
// self.showLoadingVisible(false);
// self.snackbar("QRCode telah dibuat");
}
});
} catch (WriterException e) {
Log.e("QR.ex", "" + e.getMessage());
}
}
}).start();
}
Aggregations