118. gs.clearRect(0, 0, imgSize, imgSize);
119.
120. // 设定图像颜色> BLACK
121. gs.setColor(Color.BLACK);
122. // 设置偏移量,不设置可能导致解析出错
123. int pixoff = 2;
124. // 输出内容> 二维码
125. if (contentBytes.length > 0 && contentBytes.length < 800) {
126. boolean[][] codeOut = qrcodeHandler.calQrcode(contentBytes)
;
127. for (int i = 0; i < codeOut.length; i++) {
128. for (int j = 0; j < codeOut.length; j++) {
129. if (codeOut[j][i]) {
130. gs.fillRect(j * 3 + pixoff, i * 3 + pixoff, 3,
3);
131. }
132. }
133. }
134. } else {
135. throw new Exception("QRCode content bytes length = " + cont
entBytes.length + " not in [0, 800].");
136. }
137. gs.dispose();
138. bufImg.flush();
139. } catch (Exception e) {
140. e.printStackTrace();
141. }
142. return bufImg;
143. }
144.
145. /**
146. * 解析二维码(QRCode)
147. * @param imgPath 图片路径
148. * @return
149. */
150. public String decoderQRCode(String imgPath) {
151. // QRCode 二维码图片的文件
152. File imageFile = new File(imgPath);
153. BufferedImage bufImg = null;
154. String content = null;
155. try {
156. bufImg = ImageIO.read(imageFile);
157. QRCodeDecoder decoder = new QRCodeDecoder();