int barsize = -1;
Writer writer = new MultiFormatWriter();
try {
Map<EncodeHintType, Object> hints = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");
QRCode code = Encoder.encode(paymentString, ErrorCorrectionLevel.M, hints);
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
barsize = size / (code.getMatrix().getWidth() + 8);
matrix = writer.encode(paymentString, com.google.zxing.BarcodeFormat.QR_CODE, w, h, hints);
} catch (com.google.zxing.WriterException e) {
System.out.println(e.getMessage());
}