I am currently working on a simple application that transfers screenshots across sockets. I get the screenshot by instantiating and using the Robot class as follows:
private Robot robot;
public Robot getRobot(){
if(robot == null){
try{
robot = new Robot();
}catch(Exception e){}
}
return robot;
}
public BufferedImage screenshot(){
return getRobot().createScreenCapture(getScreenRectangle());
}
public byte[] getBytes(BufferedImage image){
byte[] data = null;
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "PNG", baos);
data = baos.toByteArray();
baos.close();
}catch(IOException e){}
return data;
}
I then use the getBytes
method above to convert the BufferedImage
to a byte array which is then written to the socket output stream. The image is an average of 500KB. Would it be more efficient to split this 500KB into smaller segments of say 5KB or would it be better to keep it in larger chunks of say 30KB. My main aim here is speed and accuracy of delivery. I would also appreciate any reasoning of why either way would be more effective in these terms that the other.