ZXing還滿方便的,產生各式條碼跟讀取,可以參考一下。
這裡介紹QRCode的產生方式
1.下載 ZXing
2.解開會出現很多目錄,將core及javase裡面的core.jar及javase.jar檔案include進來
3.部分程式碼
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
....
MultiFormatWriter writer = new MultiFormatWriter();
Hashtable hints = new Hashtable();
hints.put( EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q );
try {
MatrixToImageWriter.writeToFile( writer.encode( "Hello World", BarcodeFormat.QR_CODE, 800, 800, hints ),
"png", new File( "qrcode.png" ) );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
很簡單吧....BarcodeFormat有很多樣式的條碼,也有CODE_39等等可以玩玩看喔
希望我能持之以恆的寫Blog下去....動力ㄚ....
這裡介紹QRCode的產生方式
1.下載 ZXing
2.解開會出現很多目錄,將core及javase裡面的core.jar及javase.jar檔案include進來
3.部分程式碼
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
....
MultiFormatWriter writer = new MultiFormatWriter();
Hashtable hints = new Hashtable();
hints.put( EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q );
try {
MatrixToImageWriter.writeToFile( writer.encode( "Hello World", BarcodeFormat.QR_CODE, 800, 800, hints ),
"png", new File( "qrcode.png" ) );
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WriterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
很簡單吧....BarcodeFormat有很多樣式的條碼,也有CODE_39等等可以玩玩看喔
希望我能持之以恆的寫Blog下去....動力ㄚ....
留言
張貼留言