Link

Change pixel depth and ColorSpace of an Image

It is possible to change the ColorSpace and bit depth used by an image with JDeli. This will alter both the appearance and output image size.

Image types supported by Java

Java provides a generic BufferedImage type which can have multiple types. The current type of a BufferedImage is easily discovered with this code

image.getType(); //returns an int value

Recommended values are:

BufferedImage.TYPE_INT_RGB (1)
24 bit colour using 3 bytes per pixel
BufferedImage.TYPE_INT_ARGB (2)
24 bit colour with opacity using 4 bytes per pixel
BufferedImage.TYPE_BYTE_GRAY(10)
255 shades of gray with 1 byte per pixel
BufferedImage.TYPE_BYTE_BINARY (12)
Black or white with 1 bit per pixel
BufferedImage.TYPE_BYTE_INDEXED (13)
Up to 256 colours with a lookuptable and 1 byte per pixel

Changing ColorSpace

A BufferedImage can be changed to another ColorSpace using the JDeli.process operation. If the image is already in that ColorSpace, no changes will be made.

Convert a BufferedImage to Binary example

img = JDeli.process(new ImageProcessingOperations().toBinary(), img);

Convert a BufferedImage to GrayScale example

img = JDeli.process(new ImageProcessingOperations().toGrayscale(), img);

Convert a BufferedImage to Indexed example

img = JDeli.process(new ImageProcessingOperations().toIndexed(), img);

Convert a BufferedImage to ARGB example

img = JDeli.process(new ImageProcessingOperations().toARGB(), img);

Convert a BufferedImage to RGB example

img = JDeli.process(new ImageProcessingOperations().toRGB(), img);

View Javadoc on the ColorSpace and bit depth operations