The following source, note do not put in the same folder, choose the Chinese encoding format "Utf-8"
Pay attention to the reading of the string, indicating that the novice to do the first gadget is very excited, although copied some source code, but the sweep out is still very cool
Package com.kt.twobarimage;
Import Com.swetake.util.Qrcode;
Import Java.awt.Color;
Import Java.awt.Graphics2D;
Import Java.awt.image.BufferedImage;
Import Java.io.DataInputStream;
Import Java.io.File;
Import java.io.IOException;
Import Javax.imageio.ImageIO;
Import Java.io.DataInputStream;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import java.io.IOException;
Import Java.io.InputStreamReader;
public class Createtwobarimage {
public void Creattxm (String param) throws Exception {
QRCode QRCode = new QRCode ();
Qrcode.setqrcodeerrorcorrect (' M ');
Qrcode.setqrcodeencodemode (' B ');
Qrcode.setqrcodeversion (7);
Byte[] BSTR = Param.getbytes ("UTF-8");
BufferedImage bi = new BufferedImage (139, 139,BUFFEREDIMAGE.TYPE_INT_RGB);
Graphics2D g = bi.creategraphics ();
G.setbackground (Color.White); Background color
G.clearrect (0, 0, 139, 139);
G.setcolor (Color.Black); Barcode Color
if (bstr.length > 0 && bstr.length < 123) {
Boolean[][] B = Qrcode.calqrcode (BSTR);
for (int i = 0; i < b.length; i++) {
for (int j = 0; J < B.length; J + +) {
if (B[j][i]) {
G.fillrect (J * 3 + 2, I * 3 + 2, 3, 3);
}
}
}
}
G.dispose ();
Bi.flush ();
String FilePath = "d:/images/" +param.substring (0,5) + ". jpg";
File F = new file (FilePath);
Imageio.write (BI, "JPG", f);
}
public static void Main (String args[]) {
DataInputStream din = null;
try{
InputStreamReader is = new InputStreamReader (New FileInputStream ("E:/input/test.txt"), "Utf-8");
String str1 = "";
String str2 = "";
int i =-1;
while ((I=is.read ())!=-1) {
char m = (char) i;
str2 = string.valueof (m);
STR1 = STR1+STR2;
}
try {
New Createtwobarimage (). CREATTXM (STR1);
} catch (Exception e) {
E.printstacktrace ();
}
Is.close ();
}catch (Exception e) {
E.printstacktrace ();
}
Final behavior---close flow ~
finally{
try{
if (DIN! = null) {
Din.close ();
}
}catch (IOException e) {
E.printstacktrace ();
}
}
}
}
Java implementation from TXT file read input information output QR code