废话少说直接代码:
package com.xxwan.utils;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Joy {
private static final String FOLDER = "C:\\joy";
/**
* @param args
*/
public static void main(String[] args) {
File fA = new File(FOLDER + "\\a.jpg");//背景图片
File fB = new File(FOLDER + "\\b.png");//logo图片
try {
BufferedImage imA = ImageIO.read(fA);
BufferedImage imB = ImageIO.read(fB);
int[] arrayImA = new int[imA.getWidth()*imA.getHeight()];
arrayImA = imA.getRGB(0, 0, imA.getWidth(), imA.getHeight(), arrayImA, 0, imA.getWidth());
int[] arrayImB = new int[imB.getWidth()*imB.getHeight()];
arrayImB = imB.getRGB(0, 0, imB.getWidth(), imB.getHeight(), arrayImB, 0, imB.getWidth());
BufferedImage newImg = new BufferedImage(imA.getWidth(), imA.getHeight(), BufferedImage.TYPE_INT_RGB);
// newImg.setRGB(0, 0, imA.getWidth(), imA.getHeight(), arrayImA, 0, imA.getWidth());
// newImg.setRGB(imA.getWidth(), imA.getHeight(), imB.getWidth(), imB.getHeight(), arrayImB, 0, imB.getWidth());
//alpha
Graphics2D g = newImg.createGraphics();
g.drawImage(imA, 0, 0, imA.getWidth(), imA.getHeight(),null);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP,0.5f));
g.drawImage(imB, imA.getWidth()-imB.getWidth(), imA.getHeight()-imB.getHeight(), imB.getWidth(), imB.getHeight(), null);
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER));
File out = new File(FOLDER + "\\new3.jpg");
ImageIO.write(newImg, "jpg", out);
} catch (IOException e) {
e.printStackTrace();
}
}
}
无聊打发时间。。。。。。。。。。。。。。。。。。。。。。。