Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2011 03:24
Show Gist options
  • Save anonymous/779123 to your computer and use it in GitHub Desktop.
Save anonymous/779123 to your computer and use it in GitHub Desktop.
public static void main(String[] args) {
Charset charset = Charset.forName("ISO-8859-1");
CharsetEncoder encoder = charset.newEncoder();
byte[] b = null;
try {
// Convert a string to ISO-8859-1 bytes in a ByteBuffer
ByteBuffer bbuf = encoder.encode(CharBuffer.wrap("hello world"));
b = bbuf.array();
} catch (CharacterCodingException e) {
System.out.println(e.getMessage());
}
String data;
try {
data = new String(b, "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
System.out.println(e.getMessage());
}
// get a byte matrix for the data
BitMatrix matrix = null;
int h = 100;
int w = 100;
com.google.zxing.Writer writer = new QRCodeWriter();
try {
matrix = writer.encode(data,
com.google.zxing.BarcodeFormat.QR_CODE, w, h);
} catch (com.google.zxing.WriterException e) {
System.out.println(e.getMessage());
}
String filePath = "C:\\temp\\qr_png.png";
File file = new File(filePath);
try {
MatrixToImageWriter.writeToFile(matrix, "PNG", file);
System.out.println("printing to " + file.getAbsolutePath());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
@mzamoun
Copy link

mzamoun commented Mar 7, 2013

quelles libs utilisées ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment