一区二区三区日韩精品-日韩经典一区二区三区-五月激情综合丁香婷婷-欧美精品中文字幕专区

分享

java生成二維碼

 instl 2014-11-15
  [java]
  package org.lxh;
  import com.google.zxing.common.BitMatrix;
  import javax.imageio.ImageIO;
  import java.io.File;
  import java.io.OutputStream;
  import java.io.IOException;
  import java.awt.image.BufferedImage;
  public final class MatrixToImageWriter {
  private static final int BLACK = 0xFF000000;
  private static final int WHITE = 0xFFFFFFFF;
  private MatrixToImageWriter() {}
  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);
  }
  }
  }
package org.lxh;
  import com.google.zxing.common.BitMatrix;
  import javax.imageio.ImageIO;
  import java.io.File;
  import java.io.OutputStream;
  import java.io.IOException;
  import java.awt.image.BufferedImage;
  public final class MatrixToImageWriter {
  private static final int BLACK = 0xFF000000;
  private static final int WHITE = 0xFFFFFFFF;
  private MatrixToImageWriter() {}
  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);
  }
  }
  }
4.借助上面的類生成二維碼
  [java]
  package org.lxh;
  import java.io.File;
  import java.util.Hashtable;
  import com.google.zxing.BarcodeFormat;
  import com.google.zxing.EncodeHintType;
  import com.google.zxing.MultiFormatWriter;
  import com.google.zxing.WriterException;
  import com.google.zxing.common.BitMatrix;
  public class Test {
  /**
  * @param args
  * @throws Exception
  */
  public static void main(String[] args) throws Exception {
  String text = "http://www.";
  int width = 300;
  int height = 300;
  //二維碼的圖片格式
  String format = "gif";
  Hashtable hints = new Hashtable();
  //內(nèi)容所使用編碼
  hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
  BitMatrix bitMatrix = new MultiFormatWriter()。encode(text,
  BarcodeFormat.QR_CODE, width, height, hints);
  //生成二維碼
  File outputFile = new File("d:"+File.separator+"new.gif");
  MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);
  }
  }
 

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多

    亚洲天堂精品1024| 国产级别精品一区二区视频| 偷拍美女洗澡免费视频| 国产日产欧美精品视频| 91人妻人人揉人人澡人| 亚洲五月婷婷中文字幕| 不卡中文字幕在线视频| 亚洲一区二区亚洲日本| 久草热视频这里只有精品| 丝袜诱惑一区二区三区| 日本丰满大奶熟女一区二区| 日韩免费成人福利在线| 欧美av人人妻av人人爽蜜桃| 国产女同精品一区二区| 91久久精品国产一区蜜臀| 日本人妻精品中文字幕不卡乱码| 欧美小黄片在线一级观看| 国产一级内片内射免费看| 日本加勒比系列在线播放| 国产高清一区二区不卡| 日韩精品第一区二区三区| 中文字幕中文字幕在线十八区| 午夜色午夜视频之日本| 日本精品最新字幕视频播放| 青青免费操手机在线视频| 日本av在线不卡一区| 翘臀少妇成人一区二区| 久热在线视频这里只有精品| 伊人久久青草地综合婷婷| 精品少妇人妻一区二区三区| 中文字幕熟女人妻视频| 老鸭窝老鸭窝一区二区| 两性色午夜天堂免费视频| 久久精品国产99国产免费| 亚洲精品成人福利在线| 亚洲高清中文字幕一区二三区 | 国产精品激情对白一区二区| 日本高清不卡一二三区| 国产成人亚洲欧美二区综| 美国女大兵激情豪放视频播放| 欧美日韩一级黄片免费观看|