The second argument of the write method defines the image quality:
- JPEG: The compression quality is a number between 0.0 -> 1.0. Usually, the value 0.8 is a good compromise between quality and image file size.
- GIF: The number of colors is between 1 and 256.
Therefore, the correct code is as follows:
layer.write(imageBean.getImageType() , 256, cqResponse.getOutputStream());