1. download 2 Zxing jar libraries (core-2.2.jar, javase-2.2.jar) from Maven release repository
2. write the simple code
package com.abc.def;
import java.io.IOException;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
public class QRGen {
public static void main (String[] args){
QRCodeWriter writer = new QRCodeWriter();
BitMatrix bitMatrix = null;
try {
bitMatrix = writer.encode("http://google.come",
BarcodeFormat.QR_CODE, 300, 300);
MatrixToImageWriter.writeToFile(bitMatrix,
"png", new File("/tmp/qrcode.png"));
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
3. build and run it !
0 意見:
張貼留言