use of com.google.zxing.qrcode.QRCodeWriter in project krypton-android by kryptco.
the class MemberQR method onCreateClient.
@Subscribe(threadMode = ThreadMode.MAIN)
public void onCreateClient(TeamService.GenerateClientResult r) {
if (r.c.error != null) {
Error.shortToast(getContext(), r.c.error);
Transitions.beginFade(this).remove(this).commitAllowingStateLoss();
return;
}
Sigchain.Identity identity = r.c.success;
Sigchain.MemberQRPayload memberQRPayload = new Sigchain.MemberQRPayload(identity.email, identity.publicKey);
Sigchain.QRPayload qrPayload = new Sigchain.QRPayload(memberQRPayload);
try {
BitMatrix qrData = new QRCodeWriter().encode(JSON.toJson(qrPayload), BarcodeFormat.DATA_MATRIX.QR_CODE, 500, 500);
qr.setImageBitmap(new BarcodeEncoder().createBitmap(qrData));
qrPayloads.set(new QRPayloads(memberQRPayload, MemberScan.lastScannedPayload.get()));
loadQRProgress.setAlpha(0);
joinProgress.animate().setDuration(1000).alpha(1).start();
new JoinTeamProgress(getContext()).updateTeamData((s, d) -> {
d.identity = identity;
d.teamName = qrPayloads.get().admin.teamName;
return s;
});
} catch (WriterException e) {
e.printStackTrace();
Error.shortToast(getContext(), "Error creating QRCode");
Transitions.beginFade(this).remove(this).commitAllowingStateLoss();
return;
}
EventBus.getDefault().post(new PollRead());
}
use of com.google.zxing.qrcode.QRCodeWriter in project mycore by MyCoRe-Org.
the class MCRQRCodeServlet method getPNGContent.
private MCRContent getPNGContent(final String url, final int size) throws IOException {
QRCodeWriter writer = new QRCodeWriter();
BitMatrix matrix;
try {
matrix = writer.encode(url, BarcodeFormat.QR_CODE, size, size);
} catch (WriterException e) {
throw new IOException(e);
}
BufferedImage image = toBufferedImage(matrix);
return pngTools.toPNGContent(image);
}
use of com.google.zxing.qrcode.QRCodeWriter in project i2p.i2p-bote by i2p.
the class QrCodeUtils method getQRCodeBitmap.
/**
* Generate Bitmap with QR Code based on input.
*
* @param input The data to render as a QR code.
* @param size The preferred width and height of the QR code in pixels.
* @return QR Code as Bitmap
*/
public static Bitmap getQRCodeBitmap(final String input, final int size) {
try {
final Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
final BitMatrix result = new QRCodeWriter().encode(input, BarcodeFormat.QR_CODE, size, size, hints);
final int width = result.getWidth();
final int height = result.getHeight();
final int[] pixels = new int[width * height];
for (int y = 0; y < height; y++) {
final int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = result.get(x, y) ? Color.BLACK : Color.WHITE;
}
}
final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
} catch (final WriterException e) {
Log log = I2PAppContext.getGlobalContext().logManager().getLog(QrCodeUtils.class);
if (log.shouldLog(Log.ERROR))
log.error("QrCodeUtils", e);
return null;
}
}
use of com.google.zxing.qrcode.QRCodeWriter in project wechat by motianhuo.
the class GetMoneyActivity method generateQRCode.
private Bitmap generateQRCode(String content) {
try {
QRCodeWriter writer = new QRCodeWriter();
// MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix matrix = writer.encode(content, BarcodeFormat.QR_CODE, 500, 500);
return bitMatrix2Bitmap(matrix);
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
use of com.google.zxing.qrcode.QRCodeWriter in project android-zxingLibrary by yipianfengye.
the class CodeUtils method createImage.
/**
* 生成二维码图片
* @param text
* @param w
* @param h
* @param logo
* @return
*/
public static Bitmap createImage(String text, int w, int h, Bitmap logo) {
if (TextUtils.isEmpty(text)) {
return null;
}
try {
Bitmap scaleLogo = getScaleLogo(logo, w, h);
int offsetX = w / 2;
int offsetY = h / 2;
int scaleWidth = 0;
int scaleHeight = 0;
if (scaleLogo != null) {
scaleWidth = scaleLogo.getWidth();
scaleHeight = scaleLogo.getHeight();
offsetX = (w - scaleWidth) / 2;
offsetY = (h - scaleHeight) / 2;
}
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
// 容错级别
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
// 设置空白边距的宽度
hints.put(EncodeHintType.MARGIN, 0);
BitMatrix bitMatrix = new QRCodeWriter().encode(text, BarcodeFormat.QR_CODE, w, h, hints);
int[] pixels = new int[w * h];
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (x >= offsetX && x < offsetX + scaleWidth && y >= offsetY && y < offsetY + scaleHeight) {
int pixel = scaleLogo.getPixel(x - offsetX, y - offsetY);
if (pixel == 0) {
if (bitMatrix.get(x, y)) {
pixel = 0xff000000;
} else {
pixel = 0xffffffff;
}
}
pixels[y * w + x] = pixel;
} else {
if (bitMatrix.get(x, y)) {
pixels[y * w + x] = 0xff000000;
} else {
pixels[y * w + x] = 0xffffffff;
}
}
}
}
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, w, 0, 0, w, h);
return bitmap;
} catch (WriterException e) {
e.printStackTrace();
}
return null;
}
Aggregations