java 使用zxing生成二维码
来源:互联网 发布:gson解析json文件 编辑:程序博客网 时间:2024/05/16 08:20
import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import java.io.OutputStream;import java.util.HashMap;import java.util.Hashtable;import java.util.Map;import javax.imageio.ImageIO;import com.google.zxing.BarcodeFormat;import com.google.zxing.EncodeHintType;import com.google.zxing.MultiFormatWriter;import com.google.zxing.common.BitMatrix;/** * java生成二维条码 * * @author Administrator * */public class ZxingHandler {private static final int BLACK = 0xFF000000;private static final int WHITE = 0xFFFFFFFF;public static BufferedImage toBufferedImage(BitMatrix matrix) {int width = matrix.getWidth();int height = matrix.getHeight();BufferedImage image = new BufferedImage(width, height,BufferedImage.TYPE_INT_RGB);for (int x = 0; x < width; x++) {for (int y = 0; y < height; y++) {image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);}}return image;}public static void writeToFile(BitMatrix matrix, String format, File file)throws IOException {BufferedImage image = toBufferedImage(matrix);if (!ImageIO.write(image, format, file)) {throw new IOException("Could not write an image of format "+ format + " to " + file);}}public static void writeToStream(BitMatrix matrix, String format,OutputStream stream) throws IOException {BufferedImage image = toBufferedImage(matrix);if (!ImageIO.write(image, format, stream)) {throw new IOException("Could not write an image of format "+ format);}}/** * * 主函数 */public static void main(String[] args) {try {String content = "tv01 = {*/*/*//*/**/}(TextView) this.findViewById(R.id.textView1)啦顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶顶啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦啦快快快快快快快快快快快";String path = "D:/";MultiFormatWriter multiFormatWriter = new MultiFormatWriter();Hashtable hints = new Hashtable();hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");BitMatrix bitMatrix = multiFormatWriter.encode(content,BarcodeFormat.QR_CODE, 54, 54, hints);File file1 = new File(path, "ccc.jpg");ZxingHandler zx = new ZxingHandler();zx.writeToFile(bitMatrix, "jpg", file1);} catch (Exception e) {e.printStackTrace();}}}
0 0
- java 使用zxing 生成二维码
- java 使用zxing生成二维码
- java 使用zxing 生成二维码
- java使用zxing生成二维码
- 【JAVA】使用ZXing生成二维码
- java 使用zxing生成二维码
- java 使用zxing 生成二维码
- java 使用ZXing生成二维码
- java使用zxing生成二维码
- Java实现二维码-使用Zxing生成二维码
- java实现二维码生成,使用Google zxing
- java中,使用zxing生成二维码
- java入门--使用zxing生成二维码链接
- Java使用zxing生成解读QRcode二维码
- JAVA生成二维码(使用zxing方式)
- java生成二维码(使用zxing.jar)
- 使用zxing生成二维码
- 使用ZXing生成二维码
- fedora21下ssh和防火墙设置
- Android四大组件——Activity
- AutoLayout后想setFrame控件
- WPF 中控件的变形
- CocoaPods安装、使用
- java 使用zxing生成二维码
- Android属性动画Property Animation系列二之ObjectAnimator
- STM32F4——FLASH闪存编程原理
- openlayer2.X通过WMTS服务加载ArcGIS服务
- loadrunner 11.0录制脚本时,事件为空,录制脚本速度慢等问题小结
- ubuntu 下vim修改tab键为4个空格
- memory pool 原理及使用
- swift学习- 协议(二十二)
- test