Slide 15
Slide 15 text
public Bitmap createQRCodeByZxing(String contents, int size) throws WriterException {
QRCodeWriter qrWriter = new QRCodeWriter();
// ҟͳΔܕͷΛೖΕΔͨΊgeneric͑ͳ͍
@SuppressWarnings("rawtypes")
Hashtable encodeHint = new Hashtable();
encodeHint.put(EncodeHintType.CHARACTER_SET, "shiftjis");
// Τϥʔम෮ϨϕϧΛࢦఆ
encodeHint.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
BitMatrix qrCodeData = qrWriter.encode(contents, BarcodeFormat.QR_CODE, size, size,
encodeHint);
// QRίʔυͷbitmapը૾Λੜ
Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
bitmap.eraseColor(Color.argb(255, 255, 255, 255));
for(int x = 0; x < qrCodeData.getWidth(); x++) {
for(int y = 0; y < qrCodeData.getHeight(); y++) {
if(qrCodeData.get(x, y)) {
// trueBlack
bitmap.setPixel(x, y, Color.BLACK);
} else {
// falseWhite
bitmap.setPixel(x, y, Color.WHITE);
}
}
}
return bitmap;
}
128݄25༵