您的位置:首页 > 其它

详解内存工作原理及发展历程(2)

2008-09-24 00:05 441 查看
1.jar包下载http://ishare.iask.sina.com.cn/download/explain.php?fileid=35428376
package ewm;

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

{

/** Creates a new instance of QRCodeEncoderTest */

public QRCodeEncoderTest()

{

}

public static void create_image(String name, String info) throws Exception {
try {
Qrcode testQrcode = new Qrcode();
testQrcode.setQrcodeErrorCorrect('M');
testQrcode.setQrcodeEncodeMode('B');
testQrcode.setQrcodeVersion(7);
byte[] d = info.getBytes("gbk");
System.out.println(d.length);
BufferedImage bi = new BufferedImage(98, 98,
BufferedImage.TYPE_INT_RGB);
//BufferedImage bi = new BufferedImage(98, 98,
//BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = bi.createGraphics();
g.setColor.WHITE);< /span>
g.clearRect(0, 0, 98, 98);
// 设定图像颜色:BLACK
g.setColor(Color.RED);
// 设置偏移量 不设置肯能导致解析出错
int pixoff = 3;
// 输出内容:二维码
// 限制最大字节数为120
if (d.length > 0 && d.length < 120) {
boolean[][] s = testQrcode.calQrcode(d);
for (int i = 0; i < s.length; i++) {

for (int j = 0; j < s.length; j++) {
if (s[j][i]) {
g.fillRect(j * 2 + pixoff, i * 2 + pixoff, 2, 2);
}
}
}
}
g.dispose();
bi.flush();
File f = new File("F:\\" + name + ".jpg");
if (!f.exists()) {
f.createNewFile();
}
// 创建图片
ImageIO.write(bi, "jpg", f);
} // end try
catch (Exception e) {

e.printStackTrace();

} // end catch

}

public static void main(String[] args) throws Exception {
QRCodeEncoderTest.create_image("ewm", "http://hao.360.cn/" + "");

} // end main

}

本文出自 “Java-Baby” 博客,请务必保留此出处http://yzbxcf.blog.51cto.com/4142491/1207732
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: