I am trying to make a screen recording app. I have code that takes a screenshot using java.awt.Robot.createScreenCapture
and then stores the output in an arraylist. The arraylist needs to store 7500 images. I need to be able to access any of the BufferedImages
very quickly. I have tried converting the BufferedImages
into byte[]
and then storing them, but converting them back to bufferedimages takes too long (about 1 second). Is there a way I could do this without having to add command line arguments?
Error:
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
Code:
static ArrayList < BufferedImage > bilist = new ArrayList < BufferedImage > ();
public static Timer recordingTimer = new Timer (40, new ActionListener () {
public void actionPerformed ( ActionEvent e ) {
try {
BufferedImage bimage = robot.createScreenCapture(wholescreen);
bilist.add(bimage);
if ( bilist.size() > 7500 ) bilist.remove(7500);
} catch ( Exception ex ) {
ex.printStackTrace();
}
}
});