




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、Zxing是Google提供的關(guān)于條碼(一維碼、二維碼)的解析工具,提供了二維碼的生成與解析的方法,現(xiàn)在我簡(jiǎn)單介紹一下使用Java利用Zxing生成與解析二維碼Jar包下載:/question/tag/zxing1、二維碼的生成1.1 將Zxing-core.jar 包加入到classpath下(如果是Domino平臺(tái),請(qǐng)參考本人的文庫(kù):/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ě)解析二維碼的實(shí)現(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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 文化徒步活動(dòng)方案
- 文安理發(fā)活動(dòng)方案
- 春節(jié)女裝活動(dòng)方案
- 文體活動(dòng)方案活動(dòng)方案
- 春天居家親子活動(dòng)方案
- 新能源品鑒活動(dòng)方案
- 春季產(chǎn)品巡展活動(dòng)方案
- 文博會(huì)創(chuàng)意活動(dòng)方案
- 教育云介紹課件
- 新春服飾活動(dòng)策劃方案
- 專題 完形填空 七年級(jí)英語(yǔ)下冊(cè)期末復(fù)習(xí)考點(diǎn)培優(yōu)專項(xiàng)北師大版(2024版)(含答案解析)
- 余料使用管理制度
- 2025至2030年中國(guó)彩涂鋁材行業(yè)市場(chǎng)動(dòng)態(tài)分析及發(fā)展趨向研判報(bào)告
- 農(nóng)業(yè)面源防治課件
- 2025至2030中國(guó)氨基吡啶行業(yè)項(xiàng)目調(diào)研及市場(chǎng)前景預(yù)測(cè)評(píng)估報(bào)告
- 2025-2030中國(guó)商業(yè)展示道具市場(chǎng)應(yīng)用前景及投資價(jià)值評(píng)估報(bào)告
- 拉薩市墨竹工卡縣思金拉措小學(xué)-2025年春季英語(yǔ)教研組工作總結(jié)-一路求索不停歇【課件】
- 山東省菏澤市2023?2024學(xué)年高一下學(xué)期7月期末考試 數(shù)學(xué)試題(含解析)
- (三級(jí))人工智能訓(xùn)練師職業(yè)技能鑒定理論考試題(附答案)
- 2025杭州市臨安區(qū)事業(yè)單位招聘80人考前自測(cè)高頻考點(diǎn)模擬試題附答案詳解(鞏固)
- 2025年北京二十中中考英語(yǔ)零模試卷
評(píng)論
0/150
提交評(píng)論