java實(shí)現(xiàn)合并圖片的方法示例-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!

創(chuàng)新互聯(lián)長(zhǎng)期為近1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為歙縣企業(yè)提供專業(yè)的網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì),歙縣網(wǎng)站改版等技術(shù)服務(wù)。擁有10多年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。

本文實(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);
      // 寫(xiě)圖片
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }
}

當(dāng)前文章:java實(shí)現(xiàn)合并圖片的方法示例-創(chuàng)新互聯(lián)
分享URL:http://muchs.cn/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)

小程序開(kāi)發(fā)