![Java利用Zxing生成二維碼(Domino也適用)_第1頁](http://file1.renrendoc.com/fileroot_temp2/2020-10/8/afa81eb9-76e8-488b-b18c-561b697ab690/afa81eb9-76e8-488b-b18c-561b697ab6901.gif)
![Java利用Zxing生成二維碼(Domino也適用)_第2頁](http://file1.renrendoc.com/fileroot_temp2/2020-10/8/afa81eb9-76e8-488b-b18c-561b697ab690/afa81eb9-76e8-488b-b18c-561b697ab6902.gif)
![Java利用Zxing生成二維碼(Domino也適用)_第3頁](http://file1.renrendoc.com/fileroot_temp2/2020-10/8/afa81eb9-76e8-488b-b18c-561b697ab690/afa81eb9-76e8-488b-b18c-561b697ab6903.gif)
![Java利用Zxing生成二維碼(Domino也適用)_第4頁](http://file1.renrendoc.com/fileroot_temp2/2020-10/8/afa81eb9-76e8-488b-b18c-561b697ab690/afa81eb9-76e8-488b-b18c-561b697ab6904.gif)
![Java利用Zxing生成二維碼(Domino也適用)_第5頁](http://file1.renrendoc.com/fileroot_temp2/2020-10/8/afa81eb9-76e8-488b-b18c-561b697ab690/afa81eb9-76e8-488b-b18c-561b697ab6905.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、Zxing是Google提供的關(guān)于條碼(一維碼、二維碼)的解析工具,提供了二維碼的生成與解析的方法,現(xiàn)在我簡單介紹一下使用Java利用Zxing生成與解析二維碼Jar包下載:/question/tag/zxing1、二維碼的生成1.1 將Zxing-core.jar 包加入到classpath下(如果是Domino平臺,請參考本人的文庫:/view/e09bd825b7?fr=prin)。1.2 二維碼的生成需要借助MatrixToImageWriter類,該類是由Google提供的,可以將該類拷貝到源碼中,這
2、里我將該類的源碼貼上,可以直接使用。import mon.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 = 0xFF; private static fi
3、nal 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
4、 (int y = 0; y sourceWidth | top + height sourceHeight) throw new IllegalArgumentException(Crop rectangle does not fit within image data.); for (int y = top; y top + height; y+) for (int x = left; x left + width; x+) if (image.getRGB(x, y) & 0xFF) = 0) image.setRGB(x, y, 0xFFFFFFFF); / = white this.
5、image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY); this.image.getGraphics().drawImage(image, 0, 0, null); this.left = left; this.top = top; Override public byte getRow(int y, byte row) if (y = getHeight() throw new IllegalArgumentException(Requested row is outside th
6、e image: + y); int width = getWidth(); if (row = null | row.length width) row = new bytewidth; image.getRaster().getDataElements(left, top + y, width, 1, row); return row; Override public byte getMatrix() int width = getWidth(); int height = getHeight(); int area = width * height; byte matrix = new
7、bytearea; image.getRaster().getDataElements(left, top, width, height, matrix); return matrix; Override public boolean isCropSupported() return true; Override public LuminanceSource crop(int left, int top, int width, int height) return new BufferedImageLuminanceSource(image, this.left + left, this.to
8、p + top, width, height); Override public boolean isRotateSupported() return true; Override public LuminanceSource rotateCounterClockwise() int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth);
9、 BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY); Graphics2D g = rotatedImage.createGraphics(); g.drawImage(image, transform, null); g.dispose(); int width = getWidth(); return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (
10、left + width), getHeight(), width); 2.3 編寫解析二維碼的實現(xiàn)代碼try MultiFormatReader formatReader = new MultiFormatReader(); String filePath = C:/Users/Administrator/Desktop/testImage/test.jpg; File file = new File(filePath); BufferedImage image = ImageIO.read(file); LuminanceSource source = new BufferedImageL
11、uminanceSource(image); Binarizer binarizer = new HybridBinarizer(source); BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer); Map hints = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, UTF-8); Result result = formatReader.decode(binaryBitmap,hints); System.out.println(result = + result.toString(); System.out.println(resultFormat = + result.getBarcodeFormat(); System.out.println(resultText = + result.getText(); catch (Exception e) e.pri
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 公司在職員工培訓(xùn)服務(wù)合同書
- 礦山企業(yè)安全生產(chǎn)許可證頒發(fā)與管理作業(yè)指導(dǎo)書
- 反擔(dān)保合同協(xié)議1
- 游戲美術(shù)設(shè)計制作實戰(zhàn)手冊作業(yè)指導(dǎo)書
- 針紡織品銷售購銷合同
- 小學(xué)二年級數(shù)學(xué)上冊口算
- 2025年紹興a2貨運從業(yè)資格證模擬考試題
- 2024-2025學(xué)年高中語文專題一小說家想說些什么第1課在酒樓上學(xué)案蘇教版選修短篇小說蚜
- 七年級班級工作總結(jié)
- 四年級第一學(xué)期德育工作計劃
- 2025江蘇南京市金陵飯店股份限公司招聘高頻重點提升(共500題)附帶答案詳解
- 公共政策分析 課件匯 陳振明 第0-9章 導(dǎo)論、緒論:政策科學(xué)的“研究綱領(lǐng)”- 政策監(jiān)控
- C語言程序設(shè)計 教案
- 2025年牛津譯林版英語七年級下冊全冊單元重點知識點與語法匯編
- 《小學(xué)作文指導(dǎo)》課件
- 小學(xué)六年級數(shù)學(xué)方程應(yīng)用題100道及答案解析
- 2025新譯林版英語七年級下單詞表
- 海洋工程設(shè)備保溫保冷方案
- 主干光纜、支線光纜線路中斷應(yīng)急預(yù)案
- 跨學(xué)科主題學(xué)習(xí)的思考與策略
- 文藝演出排練指導(dǎo)服務(wù)合同
評論
0/150
提交評論