generated from sigonasr2/JavaProjectTemplate
First version of screenshot stitcher completed
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
b1cade73f4
commit
e4bb12edb9
BIN
chatlog.png
Normal file
BIN
chatlog.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 MiB |
@ -2,8 +2,12 @@ package sig;
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
@ -21,8 +25,46 @@ public class JavaProjectTemplate {
|
||||
Thread.sleep(5000);
|
||||
|
||||
//312,118 1352,889
|
||||
ImageIO.write(r.createScreenCapture(capture),"png",new File("test.png"));
|
||||
} catch (AWTException | IOException | InterruptedException e) {
|
||||
List<BufferedImage> imgs = new ArrayList<BufferedImage>();
|
||||
|
||||
boolean done=false;
|
||||
|
||||
while (!done) {
|
||||
BufferedImage res = r.createScreenCapture(capture);
|
||||
if (imgs.size()>1) {
|
||||
//Compare to make sure we haven't reached the end yet.
|
||||
BufferedImage lastImg = imgs.get(imgs.size()-1);
|
||||
int matches=0;
|
||||
outer:
|
||||
for (int x=0;x<lastImg.getWidth();x++) {
|
||||
for (int y=0;y<lastImg.getHeight();y++) {
|
||||
if (lastImg.getRGB(x, y)==res.getRGB(x, y)) {
|
||||
matches++;
|
||||
}
|
||||
if (matches>(lastImg.getWidth()*lastImg.getHeight())*0.90) { //90% match required.
|
||||
done=true;
|
||||
System.out.println("Completed! Now stitching together final image.");
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
imgs.add(res);
|
||||
r.waitForIdle();
|
||||
r.keyPress(KeyEvent.VK_PAGE_DOWN);
|
||||
r.delay(50);
|
||||
r.keyRelease(KeyEvent.VK_PAGE_DOWN);
|
||||
r.delay(1000);
|
||||
}
|
||||
|
||||
BufferedImage finalImg = new BufferedImage(capture.width,capture.height*imgs.size(),BufferedImage.TYPE_INT_ARGB);
|
||||
for (int i=0;i<imgs.size();i++) {
|
||||
finalImg.setRGB(0,i*capture.height,capture.width,capture.height,imgs.get(i).getRGB(0,0,capture.width,capture.height,null,0,capture.width),0,capture.width);
|
||||
}
|
||||
ImageIO.write(finalImg,"png",new File("..","chatlog.png"));
|
||||
|
||||
System.out.println("Done!");
|
||||
} catch (AWTException | InterruptedException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user