Created
January 14, 2011 03:24
-
-
Save anonymous/779123 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
quelles libs utilisées ?