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 3 Introducing the BufferedImage

1 min read

BufferedImage is one of the most useful Java abstractions. It hides all the complexity of different types of images whilst allowing access to the underlying data. Under the hood, a BufferedImage can be many types of image. This is the list of types visible in an IDE.

BufferedImage types

The differences between the types of BufferedImage are:-

  1. Range of Colours (Binary will give back and white only, RGB will provide 24-bit color)
  2. Opacity (only available in ARGB – the A is an 8 bit Alpha channel).
  3. Amount of memory used (ARGB uses the most as 4 bytes per pixel).
  4. Size of the saved file.

A BufferedImage generally uses the RGB, Gray or Binary Color Spaces. Data can be in other formats, and the raw raster data can be loaded and accessed for CMYK and YCCK, but the Colors will not display correctly. BufferedImage provides lots of methods to access the raw image data, including the Raster, pixel and ColorModel used.

All BufferedImages work the same, so the same code can be used to manipulate a BufferedImage. A Graphics2D drawing surface can be obtained directly from an instance of BuggeredImage with getGraphics() and used to draw shapes, text and other images over the original image. All are converted to the Image type used. So a Binary Image will only show black and white and any colors used will be converted.

BufferedImages can be converted into other supported ColorSpaces types by using a ColorConvertOp. Java can be used for Image processing either via manipulating the BufferedImage directly or the Graphics2D object.

So BufferedImage offers a really flexible abstraction which makes it very easy to make use of images in Java. Java developers no longer need to worry about image types and formats.

Java includes support to load and save images in various formats using ImageIO, and other libraries such as Apache Imaging and our JDeli library also offer this feature.

Next time we will talk more about ImageIO and other Image libraries.

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.

Did you know...

IDRsolutions offers a whole range of online file converters to convert PDF and Microsoft Excel, Word and Office Documents to HTML5, SVG or image formats?

It is free to use for single file conversions and also includes Developer links if you want to use our commercial software for bulk conversions. Find out more on this page

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 to read HEIC image files in Java with…

In this article, I will explain how to read HEIC files into Java as a BufferedImage. ImageIO does not read HEIC file types so...
Mark Stephens
1 min read

How to convert WMF files to SVG in java…

This article will show you how to convert WMF files into SVG files using our JDeli Java Image library. What is WMF? WMF is...
Amy Pearson
1 min read

How to write WebP images in Java

In this article, I will walk you through how to write out images as WebP images in Java. ImageIO does not support WebP images...
Mark Stephens
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2020. All rights reserved.