ZXing 是一個開源 Java 類庫用于解析多種格局的 1D/2D 條形碼 。 方針是可以或許對QR編碼、Data Matrix、UPC的1D條形碼進行解碼 。
需要這些哦
電腦
intellij IDEA
第一步:代碼實現 。 1第一
:建立springboot項目 。
1、利用IDEA建立springboot項目
2、利用eclipse建立springboot項目
3、添加依靠zxing依靠:
<!--java zxing二維碼(可帶logo)、條形碼生當作-->
<depency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.3</version>
</depency>
<!--解析需要依靠的架包-->
<depency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.3</version>
</depency>
2利用IDEA建立springboot項目
2利用eclipse建立springboot項目

2第二
:編纂生當作二維碼和條形碼的java類
1、具體代碼如下所示:
import java.awt.image.BufferedImage;
import java.io.File;
【java如何使用zxing識別圖片條碼】import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.ImageIO;
import com.google.zxing.common.BitMatrix;
/**
* 二維碼的生當作需要借助MatrixToImageWriter類 , 該類是由Google供給的 , 可以將該類直接拷貝到源碼中利用 , 當然你也可以本身寫個
* 出產條形碼的基類
*/
public class WriteBitMatricToFile {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private static BufferedImage toBufferedImage(BitMatrix bm) {
int width = bm.getWidth();
int height = bm.getHeight();
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_3BYTE_BGR);
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
image.setRGB(i, j, bm.get(i, j) ? BLACK : WHITE);
}
}
return image;
}
public static void writeBitMatricToFile(BitMatrix bm, String format,
File file) throws IOException {
// 生當作二維碼或者條形碼
BufferedImage image = toBufferedImage(bm);
// 設置logo圖標
// 在圖片上添加log , 若是不需要則不消執行此
LogoConfig logoConfig = new LogoConfig();
image = logoConfig.LogoMatrix(image);
try {
if (!ImageIO.write(image, format, file)) {
throw new RuntimeException("Can not write an image to file"
+ file);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 生當作不帶log的二維碼或者條形碼
*
* @param matrix
* @param format
* @param stream
* @throws IOException
*/
public static void writeToStream(BitMatrix matrix, String format,
OutputStream stream) throws IOException {
BufferedImage image = toBufferedImage(matrix);
猜你喜歡
- Excel如何制作進銷存匯總表
- 如何用Word制作書法字帖
- 怎么使用Powershell查看組策略信息
- 如何判斷貓蘚快好了
- 2個月小貓如何分辨公母
- 如何泡茶有益健康
- 暖寶寶/暖貼的正確使用方法
- 如何提升記憶力的方法
- Word使用技巧-怎么制作鋼筆字帖
- 余利寶如何設置銀行卡定時定額轉入
