Java implementation from TXT file read input information output QR code

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.