創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!
本文實(shí)例講述了java實(shí)現(xiàn)合并圖片的方法。分享給大家供大家參考,具體如下:
package com.test; import java.io.File; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; public class ImageCombineTest { public static void main(String args[]) { try { // 讀取第一張圖片 File fileOne = new File("/Users/coolcloud/Pictures/Art/lena-2.jpg"); BufferedImage ImageOne = ImageIO.read(fileOne); int width = ImageOne.getWidth(); // 圖片寬度 int height = ImageOne.getHeight(); // 圖片高度 // 從圖片中讀取RGB int[] ImageArrayOne = new int[width * height]; ImageArrayOne = ImageOne.getRGB(0, 0, width, height, ImageArrayOne, 0, width); // 對(duì)第二張圖片做相同的處理 File fileTwo = new File("/Users/coolcloud/Pictures/Art/lena-2.jpg"); BufferedImage ImageTwo = ImageIO.read(fileTwo); int[] ImageArrayTwo = new int[width * height]; ImageArrayTwo = ImageTwo.getRGB(0, 0, width, height, ImageArrayTwo, 0, width); // 生成新圖片 // BufferedImage ImageNew = new BufferedImage(width * 2, height, // BufferedImage.TYPE_INT_RGB); BufferedImage ImageNew = new BufferedImage(width*2, height*2, BufferedImage.TYPE_INT_RGB); ImageNew.setRGB(0, 0, width, height, ImageArrayOne, 0, width); // 設(shè)置左半部分的RGB // ImageNew.setRGB(width, 0, width, height, ImageArrayTwo, 0, width);// 設(shè)置右半部分的RGB // ImageNew.setRGB(0, height, width, ImageOne.getHeight()+ImageTwo.getHeight(), ImageArrayTwo, 0, width);// 設(shè)置右半部分的RGB ImageNew.setRGB(0, height, width, height, ImageArrayTwo, 0, width); // 設(shè)置右半部分的RGB File outFile = new File("/Users/coolcloud/Pictures/generatepic.jpg"); ImageIO.write(ImageNew, "png", outFile); // 寫圖片 } catch (Exception e) { e.printStackTrace(); } } }
當(dāng)前文章:java實(shí)現(xiàn)合并圖片的方法示例-創(chuàng)新互聯(lián)
分享URL:http://chinadenli.net/article36/cedipg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開(kāi)發(fā)、App設(shè)計(jì)、全網(wǎng)營(yíng)銷推廣、外貿(mào)網(wǎng)站建設(shè)、營(yíng)銷型網(wǎng)站建設(shè)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容