public void myfunction()
{
try
{
BufferedImage image = ImageIO.read(new File("first.jpg"));//first image
BufferedImage overlay = ImageIO.read(new File("second.jpg"));//second image
int w = Math.max(image.getWidth(), overlay.getWidth());
int h = Math.max(image.getHeight(), overlay.getHeight());
BufferedImage combined = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
Graphics g = combined.getGraphics();
g.drawImage(image, 0, 0, null);
g.drawImage(overlay, 0, 0, null);
//here i combined 2 images in combined.jpg
ImageIO.write(combined, "jpg", new File("DestinationPath", "combined.jpg"));//combined image
}
catch (Exception e)
{
e.printStackTrace();
}
}
//我想将这个combined.jpg提取到我之前的first.jpg和second.jpg中吗? //如何提取我结合此代码的2张图片?
答案 0 :(得分:0)
绘制第一张图像后,您可以在绘制叠加层时设置一些透明度。
float alpha = 0.75f;
int type = AlphaComposite.SRC_OVER;
AlphaComposite composite = AlphaComposite.getInstance(type, alpha);
g.setComposite(composite);