public static void main(String[] args) throws Exception { // String imgPath = "D:\\Users\\Zhangjunqiao\\3_Files"; // try { // BufferedImage image = ImageIO.read(new FileInputStream(imgPath)); // } catch (FileNotFoundException e) { // e.printStackTrace(); // } catch (IOException e) { // e.printStackTrace(); // } String content = "http://www.sinaimg.cn/dy/slidenews/8_img/2015_36/65486_439634_724233.jpg"; BufferedImage image2 = QRCodeUtil.standEncodeQr(content); try { ImageIO.write(image2, "jpg", new File("D:\\Users\\Zhangjunqiao\\3_Files\\2.jpg")); } catch (IOException e) { e.printStackTrace(); } String imgUrl = "http://www.qq1234.org/uploads/allimg/140714/3_140714160149_5.png"; // 小黄人 try { BufferedImage image3 = QRCodeUtil.createImage(content, imgUrl); ImageIO.write(image3, "jpg", new File("D:\\Users\\Zhangjunqiao\\3_Files\\3.jpg")); } catch (Exception e) { e.printStackTrace(); } File file = new File("D:\\Users\\Zhangjunqiao\\3_Files\\2.jpg"); System.out.println("解析二维码的结果为:" + QRCodeUtil.decode(file)); }
public boolean batchProductQR(int sum) { if (sum <= 0 || sum > 1000) { return false; } String imgedir = null; String os = System.getProperty("os.name"); if (os.indexOf("Window") != -1) { imgedir = WINDOWS_DIR; } else { imgedir = LINUX_DIR; } boolean flag = false; DBService db = null; PreparedStatement st = null; int error = 0; try { DES des = new DES(); des.setKey("wh#@!a59"); db = new DBService(); int n = db.getInt("SELECT MAX(url_id) FROM wht_app_url"); st = db.getConn() .prepareStatement( "insert into wht_app_url(url_id,url,imgedir,imgename,imgedirname) values(?,?,?,?,?)"); db.getConn().setAutoCommit(false); for (int i = 1; i <= sum; i++) { n = n + i; if (QRCodeUtil.encode( URLPATH + n, imgedir + "logo.png", imgedir + "QRcard" + n + ".png", true)) { st.setInt(1, n); st.setString(2, URLPATH + des.decrypt(n + "")); st.setString(3, imgedir); st.setString(4, "QRcard" + n + ".png"); st.setString(5, imgedir + "QRcard" + n + ".png"); st.addBatch(); if ((n + 1) % 50 == 0) { st.executeBatch(); st.clearBatch(); } } else { error++; } } st.executeBatch(); db.getConn().commit(); flag = true; Log.info("生成智能名片二维码失败张数:" + error); } catch (Exception e) { db.rollback(); Log.error("生成智能名片二维码出错:" + e.toString()); } finally { if (null != st) { // st.close(); st = null; } if (null != db) { db.close(); db = null; } } return flag; }