I have a simple server-side code that receives a byte array representing an image in JPEG format and returns the dimensions of the image.
public String processImage(byte[] data) {
long startTime = System.currentTimeMillis();
ByteArrayInputStream stream = new ByteArrayInputStream(data);
BufferedImage bufferedImage;
bufferedImage = ImageIO.read(stream);
int height = bufferedImage.getHeight();
int width = bufferedImage.getWidth();
long endTime = System.currentTimeMillis();
return "height="+height+" | width="+width+" | elapsed="+(endTime-startTime);
}
It works, but the problem is it's unacceptably slow. For an image that's 100KB, it's taking 6s. For an image that's 900KB, it's taking 30s. Is that expected? Is there a way to make byte array to bufferedImage conversion faster?
FYI, grabbing height/width isn't the only thing I intend to do. I eventually want to process the bufferedImage. So getting height/width was just an example code.