免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
java生成二維碼
  [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.ablanxue.com";
  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);
  }
  }
 
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Java實戰(zhàn):Java使用Zxing二維碼生成案例
java開發(fā)
Java利用Zxing生成二維碼
微信支付之掃碼支付(java版 native原生支付)
如何生成二維碼圖片
Google開源項目ZXing(二維條碼編解碼)簡單使用(Java版)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服