0
我想製作截圖,然後再滾動並再次製作截圖,然後將這兩個圖像合併爲一個,但忽略相同的元素。如何合併兩個圖像但忽略相同的元素?
我知道如何在java中合併兩個圖像,但不知道如何忽略相等部分。
public static BufferedImage joinBufferedImage(BufferedImage img1,BufferedImage img2) {
//do some calculate first
int offset = 5;
int wid = img1.getWidth()+img2.getWidth()+offset;
int height = Math.max(img1.getHeight(),img2.getHeight())+offset;
//create a new buffer and draw two image into the new image
BufferedImage newImage = new BufferedImage(wid,height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = newImage.createGraphics();
Color oldColor = g2.getColor();
//fill background
g2.setPaint(Color.WHITE);
g2.fillRect(0, 0, wid, height);
//draw image
g2.setColor(oldColor);
g2.drawImage(img1, null, 0, 0);
g2.drawImage(img2, null, img1.getWidth()+offset, 0);
g2.dispose();
return newImage;
}