① java二維碼生成的jar包誰有啊如何用java生成二維碼啊
剛剛用完 ·jar包名 google.zxing 去搜索吧
② java 如何完成二維碼的製作
參考以下代碼:
//創建BarcodeSettings實例
BarcodeSettingssettings=newBarcodeSettings();
//設置條碼類型為QR二維碼
settings.setType(BarCodeType.QR_Code);
//設置二維碼數據
settings.setData("Hello123456789");
//設置二維碼顯示數據
settings.setData2D("Hello123456789");
//設置數據類型
settings.setQRCodeDataMode(QRCodeDataMode.Alpha_Number);
//設置二維碼模型寬度
settings.setX(1.0f);
//設置二維碼糾錯級別
settings.setQRCodeECL(QRCodeECL.H);
//創建BarCodeGenerator實例
=newBarCodeGenerator(settings);
//根據settings生成圖像數據,保存至BufferedImage實例
BufferedImagebufferedImage=barCodeGenerator.generateImage();
//保存為PNG圖片
ImageIO.write(bufferedImage,"png",newFile("QRCode.png"));
System.out.println("Complete!");
需要引用Spire.Barcode for java
原文:Java 生成二維碼
③ java怎麼實現二維碼生成的jar包
二維碼沒法生成 jar 包,但可以生成.jar包或文件的路徑的二維碼
——————————————————
④ 怎麼使用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 spingmvc 怎麼生成二維碼 在頁面顯示
參考這位前輩的博客:
Zxing是Google提供的工具,提供了二維碼的生成與解析的方法,現在使用Java利用Zxing生成二維碼
1),二維碼的生成
將Zxing-core.jar 包加入到classpath下。
我的下載地址:http://i.cnblogs.com/Files.aspx 下zxing.zip包
1.RqCodeController 類
1 private static final Log logger = LogFactory.getLog(RqCodeController.class);
2
3 @RequestMapping("/gen.json")
4 public void gen(String url, HttpServletResponse response, Integer width, Integer height ) {
5
6 try {
7
8 int iWidth = (width == null?200: width);
9 int iHeight = (height==null?200: height);
10
11 MatrixToImageWriter.createRqCode(url, iWidth, iHeight
12 , response.getOutputStream());
13
14 } catch (Exception e) {
15
16 logger.error(String.format("生成二維碼失敗: url: %s", url), e);
17
18 }
19
20
21 }
2,MatrixToImageWriter類的方法
1 package com.web.util;
2
3 import java.awt.Graphics2D;
4 import java.awt.Image;
5 import java.awt.image.BufferedImage;
6 import java.io.File;
7 import java.io.IOException;
8 import java.io.OutputStream;
9 import java.util.Hashtable;
10
11 import javax.imageio.ImageIO;
12
13 import org.springframework.core.io.ClassPathResource;
14
15 import com.google.zxing.BarcodeFormat;
16 import com.google.zxing.EncodeHintType;
17 import com.google.zxing.MultiFormatWriter;
18 import com.google.zxing.WriterException;
19 import com.google.zxing.common.BitMatrix;
20
21 /**
22 * 二維碼生成工具
23 */
24 public class MatrixToImageWriter {
25
26 private static final int BLACK = 0xFF000000;
27 private static final int WHITE = 0xFFFFFFFF;
28 private static final int MARGIN = 1; //邊框
29
30 private static final String FORMAT = "png";
31
32 private MatrixToImageWriter() {
33 }
34
35 public static void createRqCode(String textOrUrl, int width, int height, OutputStream toStream)
36 throws WriterException, IOException {
37
38 Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
39 hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); // 內容所使用字元集編碼
40 hints.put(EncodeHintType.MARGIN, new Integer(MARGIN));
41
42 BitMatrix bitMatrix = new MultiFormatWriter().encode(textOrUrl, BarcodeFormat.QR_CODE, width, height, hints);
43
44 BufferedImage image = toBufferedImage(bitMatrix);
45 applyLogo(image);//應用LOGO
46
47 writeToStream(image, FORMAT, toStream);
48
49 }
50
51 private static void applyLogo(BufferedImage image) throws IOException {
52
53 Graphics2D gs = image.createGraphics();
54
55 ClassPathResource resource = new ClassPathResource("logo.png");//logo圖片
56
57 // 載入logo
58 Image img = ImageIO.read(resource.getFile());
59
60 int left = image.getWidth() / 2 - img.getWidth(null) / 2;
61 int top = image.getHeight() / 2 - img.getHeight(null) / 2;
62
63 gs.drawImage(img, left, top, null);
64 gs.dispose();
65 img.flush();
66
67 }
68
69 private static BufferedImage toBufferedImage(BitMatrix matrix) {
70 int width = matrix.getWidth();
71 int height = matrix.getHeight();
72 BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
73 for (int x = 0; x < width; x++) {
74 for (int y = 0; y < height; y++) {
75 image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE);
76 }
77 }
78 return image;
79 }
80
81 public static void writeToFile(BufferedImage image, String format, File file) throws IOException {
82
83 if (!ImageIO.write(image, format, file)) {
84 throw new IOException("Could not write an image of format " + format + " to " + file);
85 }
86 }
87
88 public static void writeToStream(BufferedImage image, String format, OutputStream stream) throws IOException {
89 if (!ImageIO.write(image, format, stream)) {
90 throw new IOException("Could not write an image of format " + format);
91 }
92 }
93
94 }
⑥ java怎麼生成二維碼
1: 使用SwetakeQRCode在Java項目中生成二維碼
這個是日本人寫的,生成的是我們常見的方形的二維碼
可以用中文
2: 使用BarCode4j生成條形碼和二維碼
barcode4j是使用datamatrix的二維碼生成演算法,為支持qr的演算法
datamatrix是歐美的標准,qr為日本的標准,
barcode4j一般生成出來是長方形的
3:zxing
zxing 這個是google的
⑦ java利用pc掃描二維碼代碼,求大神幫忙啊!!!
一般來說都會有個設備,設備會把掃描結果反饋的。
你需要確認的是設備是否有jar包提供訪問,如果沒有的話就要使用jni訪問了dll了。
還有一種情況是掃描設備就是模擬鍵盤輸入的。這樣你什麼都不用做,在輸入框里等用戶掃描就好了。
⑧ java 生產二維碼報錯
你好,你可以參考我的這段代碼,記得導入Zxing1.6.jar即可:
public static void main(String[] args) {
String myCodeText = "http://www..com";
String filePath = "d:/testqr/myQR.png";
int size = 125;
String fileType = "png";
File myFile = new File(filePath);
try {
Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix byteMatrix = qrCodeWriter.encode(myCodeText,BarcodeFormat.QR_CODE, size, size, hintMap);
int CrunchifyWidth = byteMatrix.getWidth();
BufferedImage image = new BufferedImage(CrunchifyWidth, CrunchifyWidth,
BufferedImage.TYPE_INT_RGB);
image.createGraphics();
Graphics2D graphics = (Graphics2D) image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, CrunchifyWidth, CrunchifyWidth);
graphics.setColor(Color.BLACK);
for (int i = 0; i < CrunchifyWidth; i++) {
for (int j = 0; j < CrunchifyWidth; j++) {
if (byteMatrix.get(i, j)) {
graphics.fillRect(i, j, 1, 1);
}
}
}
ImageIO.write(image, fileType, myFile);
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("\n\nYou have successfully created QR Code.");
}
記得採納哦
⑨ Java如何用代碼生成二維碼
引用spire.barcode.jar包
//創建BarcodeSettings對象
BarcodeSettingssettings=newBarcodeSettings();
//設置條碼類型為
QR二維碼settings.setType(BarCodeType.QR_Code);
//設置二維碼數據
settings.setData("Hello123456789");
//設置二維碼顯示數據
settings.setData2D("Hello123456789");
//設置數據類型
settings.setQRCodeDataMode(QRCodeDataMode.Alpha_Number);
//設置二維碼模型寬度
settings.setX(1.0f);
//設置二維碼糾錯級別settings.setQRCodeECL(QRCodeECL.H);
//創建BarCodeGenerator實例
=newBarCodeGenerator(settings);
//根據settings生成圖像數據,保存至BufferedImage
BufferedImagebufferedImage=barCodeGenerator.generateImage();
//將圖片數據保存為PNG格式
ImageIO.write(bufferedImage,"png",newFile("QRCode.png"));
⑩ 使用java如何運用混淆演算法生成二維碼
需要的jar: qrcode.jar和 qrcode_swetake.jar,以及一個工具類,下面有。
package com.sbm.wll.image;
/**
* Java 生成二維碼,解析二維碼
*/
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import com.swetake.util.Qrcode;
import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
public class Image {
/**
* 生成二維碼圖片文件
*
* @param content
* 存儲內容
* @param imgPath
* 圖片路徑
* @param imgType
* 圖片類型
* @param size
* 二維碼尺寸
*/
public void encoderQRCode(String content, String imgPath, String imgType, int size) {
try {
BufferedImage bufImg = this.qRCodeCommon(content, imgType, size);
File imgFile = new File(imgPath);
// 生成二維碼QRCode圖片
ImageIO.write(bufImg, imgType, imgFile);
System.out.println("二維碼生成成功,路徑:" + imgPath);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 生成二維碼,流輸出
*/
public void encoderQRCode(String content, OutputStream output, String imgType, int size) {
try {
BufferedImage bufImg = this.qRCodeCommon(content, imgType, size);
// 生成二維碼QRCode圖片
ImageIO.write(bufImg, imgType, output);
System.out.println("二維碼生成成功,流輸出");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 生成二維碼(QRCode)圖片的基本方法
*/
private BufferedImage qRCodeCommon(String content, String imgType, int size) {
BufferedImage bufImg = null;
try {
Qrcode qrcodeHandler = new Qrcode();
// 設置二維碼排錯率,可選L(7%)、M(15%)、Q(25%)、H(30%),排錯率越高可存儲的信息越少,但對二維碼清晰度的要求越小
qrcodeHandler.setQrcodeErrorCorrect('M');
qrcodeHandler.setQrcodeEncodeMode('B');
// 設置設置二維碼尺寸,取值范圍1-40,值越大尺寸越大,可存儲的信息越大
qrcodeHandler.setQrcodeVersion(size);
// 獲得內容的位元組數組,設置編碼格式
byte[] contentBytes = content.getBytes("utf-8");
// 圖片尺寸
int imgSize = 67 + 12 * (size - 1);
bufImg = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_RGB);
Graphics2D gs = bufImg.createGraphics();
// 設置背景顏色
gs.setBackground(Color.WHITE);
gs.clearRect(0, 0, imgSize, imgSize);
// 設定圖像顏色> BLACK
gs.setColor(Color.BLACK);
// 設置偏移量,不設置可能導致解析出錯
int pixoff = 2;
// 輸出內容> 二維碼