課程
/后端開發(fā)
/Java
/Java生成二維碼
我表示找不到這個類 MatrixToImageWritoter ? ?我的jar包里沒有?還是要單獨(dú)導(dǎo)入一個實體類?網(wǎng)上的實體類又沒有topath的方法...... 求助
2016-08-23
源自:Java生成二維碼 6-2
正在回答
還需要導(dǎo)入那個jar包啊?。?/p>
慕粉3333056
你是jar包沒有導(dǎo)入成功吧 我按著老師做的 沒有問題
這個是我寫的 你可以看看是不是這樣
package?com.imooc.zxing; import?com.google.zxing.*; import?com.google.zxing.client.j2se.BufferedImageLuminanceSource; import?com.google.zxing.client.j2se.MatrixToImageWriter; import?com.google.zxing.common.BitMatrix; import?com.google.zxing.common.HybridBinarizer; import?com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import?javax.imageio.ImageIO; import?java.awt.image.BufferedImage; import?java.io.File; import?java.nio.file.Path; import?java.util.HashMap; /** ?*?生成二維碼 ?*/ public?class?CreateQRCode?{ ????public?static?void?main(String[]?args)?{ ????????createQRCode(); //????????readQRCode(); ????} ????private?static?void?readQRCode()?{ ????????try?{ ????????????MultiFormatReader?formatReader?=?new?MultiFormatReader(); ????????????File?file?=?new?File("e:/image.png"); ????????????BufferedImage?image?=?null; ????????????image?=?ImageIO.read(file); ????????????HashMap?hashMap?=?new?HashMap(); ????????????hashMap.put(EncodeHintType.CHARACTER_SET,?"utf-8"); ????????????BinaryBitmap?binaryBitmap?=?new?BinaryBitmap(new?HybridBinarizer(new?BufferedImageLuminanceSource(image))); ????????????Result?result?=?formatReader.decode(binaryBitmap,?hashMap); ????????????System.out.println("解析結(jié)果:"+result.toString()); ????????????System.out.println("二維碼格式類型:"+result.getBarcodeFormat()); ????????????System.out.println("二維碼文本:"+result.getText()); ????????}?catch?(Exception?e)?{ ????????????e.printStackTrace(); ????????} ????} ????private?static?void?createQRCode()?{ ????????int?width?=?300; ????????int?height?=?300; ????????String?format?=?"png"; ????????String?content?=?"www.baidu.com"; ????????//定義二維碼的參數(shù) ????????HashMap?hashMap?=?new?HashMap(); ????????hashMap.put(EncodeHintType.CHARACTER_SET,?"utf-8"); ????????hashMap.put(EncodeHintType.ERROR_CORRECTION,?ErrorCorrectionLevel.M); ????????hashMap.put(EncodeHintType.MARGIN,?5); ????????try?{ ????????????BitMatrix?bitMatrix?=?new?MultiFormatWriter().encode(content,?BarcodeFormat.QR_CODE,?width,?height); ????????????Path?file?=?new?File("e:/img.png").toPath(); ????????????MatrixToImageWriter.writeToPath(bitMatrix,?format,?file); ????????}?catch?(Exception?e)?{ ????????????e.printStackTrace(); ????????} ????} }
angle_xin 提問者
慕前端8116659 回復(fù) angle_xin 提問者
舉報
二維碼無處不在,自己動手用Java生成二維碼,三種生成方式任你選
1 回答找不到或無法加載主類
1 回答下載之后找不到包
6 回答報錯異常,找不到原因
2 回答系統(tǒng)找不到指定的路徑
1 回答為什么我的會報錯誤文件路徑找不到?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-03-21
還需要導(dǎo)入那個jar包啊?。?/p>
2016-08-24
你是jar包沒有導(dǎo)入成功吧 我按著老師做的 沒有問題
這個是我寫的 你可以看看是不是這樣