Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.

How does Java handle different Images and ColorSpaces – Part 2

1 min read

Java icon

There are lots of different ways of describing Color. As developers, we are most familiar with the RGB model, where every color is defined by mixing Red, Green and Blue together. In the print world, CMYK is very common, where colors or printed by literally mixing different amounts of Cyan, Magenta, Yellow and Key (black). You may also come across other ways of describing color such as DeviceN. There are also lots of different versions of RGB.

Java is based on RGB and partially supports other ColorSpaces. The ColorSpace class itself defines lots of constants for ColorSpaces, along with some nice methods to convert to and from RGB and CIEXYZ (a mathematical ColorSpace useful for convert to and from other ColorSpaces with).

Java Colorspaces

 

ColorSpaces can be defined using a CIE profile file and if you have one for a ColorSpace you can create an instance of the ColorSpace and convert color values between ColorSpaces). But BufferedImage itself only understands a more limited subset of formats.

BufferedImage colorspaces

Java can generally load lots of image types and allow access to the raw Image data, but it does not fully understand the data – so you will get oddly coloured images.

If you wanted to view a CMYK image as a BufferedImage in Java directly, you would need to convert the Image data into RGB before you could display it properly.

Next time we will talk more about BufferedImages.

Why use JDeli?

If you are working with Images in Java, JDeli offers a range of advantages over ImageIO and alternatives, including:

  • prevents heap related JVM crashes
  • implements unsupported image formats
  • reduce output file size
  • improve read/write performance
  • supports threading
  • superior image scaling algorithms

Learn more about JDeli, or download to try it yourself.



Why do developers choose JDeli over free alternatives?

  1. Works with newer image formats such as AVIF, HEIC, JPEG XL, WEBP (AVIF next release) that are not supported in Java.
  2. Better support than alternatives for JPEG, PNG, TIFF.
  3. Process images up to 3x faster than ImageIO and other Java image libraries.
  4. Prevent JVM crashes caused by native code in other image libraries such as ImageIO.
  5. Image security as JDeli processes images on your servers with no calls to any external system or third party library.

Are you a Java Developer working with Image files?

Mark Stephens Mark has been working with Java and PDF since 1999 and is a big NetBeans fan. He enjoys speaking at conferences. He has an MA in Medieval History and a passion for reading.