Package test; import Java. io. *; import Java. util. date; import Java. AWT. *; import Java. AWT. image. *; import javax. imageIO. *; import COM. swetake. util. qrcode; public class qrcodeencodertest {public qrcodeencodertest () {} public static void create_image (string sms_info) throws exception {try {qrcode testqrcode = new qrcode (); testqrcode. setqrcodeerrorcorrect ('M'); testqrcode. setqrcodeencodemode ('B'); testqrcode. se Tqrcodeversion (20); string teststring = sms_info; byte [] d = teststring. getbytes ("GBK"); system. out. println (D. length); bufferedimage Bi = new bufferedimage (98, 98, bufferedimage. type_byte_binary); graphics2d G = Bi. creategraphics (); G. setbackground (color. white); G. clearrect (0, 0, 98, 98); G. setcolor (color. black); // The maximum number of bytes is 120if (D. length> 0 & D. length <300) {Boolean [] [] S = testqrcode. calqrcode (d); (INT I = 0; I <S. length; I ++) {for (Int J = 0; j <S. length; j ++) {If (s [J] [I]) {G. fillrect (J * 2 + 3, I * 2 + 3, 2, 2) ;}}} G. dispose (); bi. flush (); file F = new file ("D: \" + sms_info + ". jpg "); If (! F. exists () {f. createnewfile ();} // Create Image ImageIO. write (Bi, "jpg", f);} // end trycatch (exception e) {e. printstacktrace ();} // end catch} public static void main (string [] ARGs) throws exception {system. out. println (new date (); qrcodeencodertest. create_image ("qrcode"); system. out. println (new date ());}}
Jar package: