利用java實現二維碼和背景圖的合并_java

來源:互聯網
上載者:User

背景介紹:

最近我們這邊需要做一個自動產生二維碼並且還要將二維碼嵌入現有的背景模板中,一直又沒寫過這些方面的東西,突然寫還真是有點迷糊,特別是對於java圖片API並不很熟悉,所以參考了很多網友的分享,很快做出來了,現在分享一下

注意:

關於二維碼的產生方式在文章java產生帶logo的多彩二維碼  已經寫過了,大家可以合起來一起使用。

執行個體代碼:

BufferedImage image= bim;//二維碼BufferedImage bg= ImageIO.read(路徑);//擷取北京圖片Graphics2D g=bg.createGraphics();int width=image.getWidth(null) > bg.getWidth() * 5/10? (bg.getWidth() * 5/10) : image.getWidth(null);int height=image.getHeight(null) > bg.getHeight() *5 /10? (bg.getHeight() * 5/10) : image.getWidth(null);g.drawImage(image,(bg.getWidth()- width)/2,(bg.getHeight()-height)/2,width,height,null);g.dispose();bg.flush();image.flush();ImageIO.write(bg,"png", file);

二維碼的效果圖:

總結

以上就是利用java實現自動產生二維碼和現有的背景圖合并的內容,有需要的朋友們可以參考學習。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.