首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

依据内容生产条2维形码

2012-07-01 
根据内容生产条2维形码将内容转换为2维条码 ,com.google.zxing为1.5版本jar包参考:[url]http://kb.cnblogs

根据内容生产条2维形码
将内容转换为2维条码 ,com.google.zxing   为1.5版本jar包

参考:
[url]
http://kb.cnblogs.com/a/1309789/
http://easymorse.googlecode.com/svn/tags/barcode-demo-0.1/src/main/java/com/easymorse/BarcodeWriterDemo.java
http://marshal.easymorse.com/archives/2791
http://blog.csdn.net/a_b_a_b_a_b_a_b/article/details/6197636
[/url]

import java.awt.image.BufferedImage;import java.io.OutputStream;import java.util.Hashtable;import javax.imageio.ImageIO;import com.google.zxing.BarcodeFormat;import com.google.zxing.EncodeHintType;import com.google.zxing.common.ByteMatrix;import com.google.zxing.qrcode.QRCodeWriter;public class BarcodeUtils {Hashtable<EncodeHintType, String> hints;{hints = new Hashtable<EncodeHintType, String>();hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");}public Boolean generate(String content,int width,int height,OutputStream outputStream){QRCodeWriter writer = new QRCodeWriter();try {ByteMatrix matrix = writer.encode(content, BarcodeFormat.QR_CODE,width, height, hints);byte[][] matrixByte = matrix.getArray();BufferedImage bimg = new BufferedImage(width, height,BufferedImage.TYPE_BYTE_GRAY);byte[] linearbuffer = new byte[width * height];for (int y = 0,i=0; y < height; y++) {for (int x = 0; x < width; x++) {linearbuffer[i++] = matrixByte[y][x];}}bimg.getRaster().setDataElements(0, 0, width, height, linearbuffer);boolean result = ImageIO.write(bimg, "png", outputStream);return result;} catch (Exception e) {throw new RuntimeException(e);}}public static void main(String[] args) {   Boolean  result=  generate("content",200,200,new FileOutputStream("D:/123.png"));    }}

热点排行