本文目錄一覽:
- 1、java 如何完成二維碼的製作
- 2、怎麼使用java生成DataMatrix格式的二維碼?
- 3、我已經用java生成了一個二維碼了,怎樣讓掃描二維碼後,讀取到一個word文檔,大神。
- 4、java 生成二維碼後如何給該二維碼添加信息
- 5、java生成二維碼名片,內容太大,轉碼怎麼實現
java 如何完成二維碼的製作
參考以下代碼:
//創建BarcodeSettings實例
BarcodeSettings settings = new BarcodeSettings();
//設置條碼類型為QR二維碼
settings.setType(BarCodeType.QR_Code);
//設置二維碼數據
settings.setData(“Hello 123456789”);
//設置二維碼顯示數據
settings.setData2D(“Hello 123456789”);
//設置數據類型
settings.setQRCodeDataMode(QRCodeDataMode.Alpha_Number);
//設置二維碼模型寬度
settings.setX(1.0f);
//設置二維碼糾錯級別
settings.setQRCodeECL(QRCodeECL.H);
//創建BarCodeGenerator實例
BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
//根據settings生成圖像數據,保存至BufferedImage實例
BufferedImage bufferedImage = barCodeGenerator.generateImage();
//保存為PNG圖片
ImageIO.write(bufferedImage, “png”, new File(“QRCode.png”));
System.out.println(“Complete!”);
需要引用Spire.Barcode for java
原文:Java 生成二維碼
怎麼使用java生成DataMatrix格式的二維碼?
參考:
import com.spire.barcode.BarCodeGenerator;
import com.spire.barcode.BarCodeType;
import com.spire.barcode.BarcodeSettings;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class CreateDataMatrix {
public static void main(String[] args) throws Exception {
//生成BarcodeSettings實例
BarcodeSettings settings = new BarcodeSettings();
//設置條形碼類型為DataMatrix
settings.setType(BarCodeType.Data_Matrix);
//設置條形碼模型寬度
settings.setX(1.5f);
//設置數據和顯示文本
settings.setData(“ABC 123456789ABC 123456789ABC 123456789”);
settings.setData2D(“ABC 123456789ABC 123456789ABC 123456789”);
//創建BarCodeGenerator實例
BarCodeGenerator barCodeGenerator = new BarCodeGenerator(settings);
//根據settings生成圖像數據,保存至BufferedImage實例
BufferedImage bufferedImage = barCodeGenerator.generateImage();
//保存為PNG圖片
ImageIO.write(bufferedImage, “png”, new File(“DataMatrix.png”));
System.out.println(“Complete!”);
}
}
用到了spire.barcode for java庫
我已經用java生成了一個二維碼了,怎樣讓掃描二維碼後,讀取到一個word文檔,大神。
不用這麼麻煩,直接使用二維碼生成器就行了,只要上傳文檔,自動直接生成二維碼。方便有快捷。
推薦一款目前市面上比較不錯的二維碼生成工具。
登錄網站進入操作後台。
點擊添加二維碼內容。(可查看管理製作過的二維碼,如果是第一次使用直接顯示第三步的編輯頁面。
3.編輯二維碼里的內容,上傳你的文檔。
上傳完成後保存即可生成二維碼,並且生成的二維碼內容支持隨時修改,原碼不變!
希望對你有幫助!
java 生成二維碼後如何給該二維碼添加信息
java可使用zxing生成二維碼並為其添加信息。
以下是詳細步驟:
1、創建MatrixToImageWriter類
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);
}
}
}
2、生成二維碼並添加信息
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 = “”;
int width = 300;
int height = 300;
//二維碼的圖片格式
String format = “gif”;
Hashtable hints = new Hashtable();
//內容所使用編碼
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);
}
}
java生成二維碼名片,內容太大,轉碼怎麼實現
Java中字元串轉碼,根據實際運用的環境有以下三種方式 使用Java.lang.String這是最常用的方法,先用對應編碼獲取位元組,然後重新構造新編碼,示例代碼如下: String s = “清山”; byte[] b = s.getBytes(“utf-吧”);//編碼 String sa = new String(b, “gb二三一二”);//解碼:用什麼字符集編碼就用什麼字符集解碼 java.io.InputStreamReader/OutputStreamWriter:橋轉換讀寫文件的應用中,可以使用這種方式,直接在IO流構造中轉換,示例代碼如下: InputStream is = new FileInputStream(“C:/項目進度跟蹤.txt”);//文件讀取 InputStreamReader isr = new InputStreamReader(is, “utf-吧”);//解碼 OutputStream os = new FileOutputStream(“C:/項目進度跟蹤_gb二三一二.txt”);//文件輸出 OutputStreamWriter osw = new OutputStreamWriter(os, “gb二三一二”);//開始編碼 java.nio.Charset使用nio中的Charset轉換字元,示例代碼如下: Charset inSet = Charset.forName(“utf-吧”); // 解碼字符集 Charset outSet = Charset.forName(“gb二三一二”); // 編碼字符集 CharsetDecoder de = inSet.newDecoder(); // 解碼器 CharsetEncoder en = outSet.newEncoder();// 編
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/254978.html