create muti-line text qrcode

472 views
Skip to first unread message

create multi-line text qrcode

unread,
Jun 12, 2016, 5:54:10 AM6/12/16
to zxing

String text = "zxing66666";
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height, hints);

i want the scan result like this:

zxing
66666

how can i realize this ?

i add %0A and \r\n , it doesn't work .

Sean Owen

unread,
Jun 12, 2016, 8:26:03 AM6/12/16
to zxing
It does work. You didn't put any newline in your string.

create multi-line text qrcode

unread,
Jun 12, 2016, 10:33:46 PM6/12/16
to zxing
On Sunday, June 12, 2016 at 8:26:03 PM UTC+8, Sean Owen wrote:
> It does work. You didn't put any newline in your string.


i tried %0A and \r\n in my code ,i debug and found the string newline,but after write to image and then scan by wechat or QQ ,just show a blank space ,not newline.

<code>
@RequestMapping(value = "/qrcode")
public void getRqCodeNoTime(HttpServletResponse response, String code) throws {
response.setContentType("image/jpeg");
response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
int width = 300;
int height = 300;
//String newLine = "\r\n";
String newLine = "%0A";
try {


Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");

BitMatrix bitMatrix = new MultiFormatWriter().encode("zxing"+newLine+code, BarcodeFormat.QR_CODE, width, height, hints);
MatrixToImageWriter.writeToStream(bitMatrix, "jpg",
response.getOutputStream());
} catch (Exception e) {
logger.error(e);
}
}
</code>

requestUrl : http://xxxx.com/qrcode?code=something

html: <img src="requestUrl"/>

also i tried http://xxxx.com/qrcode?code=zxing%0Asomething, scan by wechat or qq , it doesn't work either

Reply all
Reply to author
Forward
0 new messages