Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. int width = iPara_size; // QRコードの横サイズ
  2. int height = iPara_size; // QRコードの縦サイズ
  3.  
  4. // 異なる型の値を入れるためgenericは使えない
  5. Hashtable<EncodeHintType, ErrorCorrectionLevel> hints = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
  6.  
  7. // 日本語を扱うためにシフトJISを指定
  8.  
  9. //エラー修復レベルを指定
  10. // ErrorCorrectionLevel.L : 7%の補正レベル
  11. // ErrorCorrectionLevel.M : 15%の補正レベル
  12. // ErrorCorrectionLevel.Q : 25%の補正レベル
  13. // ErrorCorrectionLevel.H : 30%の補正レベル
  14. hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
  15.  
  16. //QRコードをエンコードするクラス
  17. QRCodeWriter writer = new QRCodeWriter();
  18.  
  19. BitMatrix bitMatrix = writer.encode(contents, format, width, height, hints);
  20. BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
  21. ImageIO.write(image, "png", new File("/usr/local/apache-tomcat-5.5.33/webapps/ROOT/api/file/qr_code_0001/barcode.png"));
  22.  
  23. return null;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement