Reputation: 31
I want to make a screenshot and then scroll and make screenshot again, then merge these two images in one, but ignore the same elements.
I know how to merge two images in java but don't know how to ignore the equal parts.
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;
}
Upvotes: 0
Views: 120
Reputation: 6353
What you want to do is called stitching.
I would recommend to use some library that supports stitching such as OpenCV. There is a Java port of OpenCV and if you search for something like "OpenCV stitcher" you will find plenty of tutorials
Upvotes: 2