eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

1. Overview

In this tutorial, we are going to take a look at a few available image-processing libraries, and perform simple image processing operation – loading an image and drawing a shape on it.

We’ll try out AWT (and a bit of Swing) library, ImageJ, OpenIMAJ, and TwelveMonkeys.

2. AWT

AWT is a built-in Java library that allows a user to perform simple operations related to display, like creating a window, defining buttons and listeners and so on. It also includes methods that allow a user to edit images. It does not require installation since it is shipped with Java.

2.1. Loading an Image

The first thing is to create a BufferedImage object from a picture saved on our disk drive:

String imagePath = "path/to/your/image.jpg";
BufferedImage myPicture = ImageIO.read(new File(imagePath));

2.2. Editing an Image

To draw a shape on an image, we will have to use Graphics object related to loaded image. Graphics object encapsulates properties needed to perform basic rendering operations. Graphics2D is a class extending Graphics. It provides more control over two-dimensional shapes.

In this particular case, we need Graphic2D to extend shape width to make it clearly visible. We achieve it by increasing its stroke property. Then we set a color, and draw a rectangle in such way that shape will be ten px from image borders:

Graphics2D g = (Graphics2D) myPicture.getGraphics();
g.setStroke(new BasicStroke(3));
g.setColor(Color.BLUE);
g.drawRect(10, 10, myPicture.getWidth() - 20, myPicture.getHeight() - 20);

2.3. Displaying an Image

Now that we have drawn something on our image, we would like to display it. We can do it using Swing library objects. First, we create JLabel object which is representing a display area for text or/and image:

JLabel picLabel = new JLabel(new ImageIcon(myPicture));

Then add our JLabel to JPanel, which we can treat as <div></div> of Java-based GUI:

JPanel jPanel = new JPanel();
jPanel.add(picLabel);

In the end, we add everything to JFrame which is window displayed on a screen. We have to set size so that we don’t have to expand this window every time we run our program:

JFrame f = new JFrame();
f.setSize(new Dimension(myPicture.getWidth(), myPicture.getHeight()));
f.add(jPanel);
f.setVisible(true);

3. ImageJ

ImageJ is a Java-based software created for working with images. It has quite a lot of plugins, available here. We will be using API only, as we want to perform processing by ourselves.

It is quite a powerful library, better than Swing and AWT, as it’s creation purpose was image processing and not GUI operations. Plugins contain many free to use algorithms, which is a good thing when we want to learn image processing and quickly see the results, rather than solve math and optimization problems laying under IP algorithms.

3.1. Maven Dependency

To start working with ImageJ, simply add a dependency to your project’s pom.xml file:

<dependency>
    <groupId>net.imagej</groupId>
    <artifactId>ij</artifactId>
    <version>1.51h</version>
</dependency>

You will find the newest version in the Maven repository.

3.2. Loading an Image

To load the image, you need to use the openImage() static method, from IJ class:

ImagePlus imp = IJ.openImage("path/to/your/image.jpg");

3.3. Editing an Image

To edit an image, we will have to use methods from ImageProcessor object attached to our ImagePlus object. Think of it as about Graphics object in AWT:

ImageProcessor ip = imp.getProcessor();
ip.setColor(Color.BLUE);
ip.setLineWidth(4);
ip.drawRect(10, 10, imp.getWidth() - 20, imp.getHeight() - 20);

3.4. Displaying an Image

You only need to call show() method of ImagePlus object:

imp.show();

4. OpenIMAJ

OpenIMAJ is set of Java libraries focused not only on computer vision and video processing but also machine learning, audio processing, working with Hadoop and much more. All parts of the OpenIMAJ project can be found here, under “Modules.” We need only the image processing part.

4.1. Maven Dependency

To start working with OpenIMAJ, simply add a dependency to your project’s <em>pom.xml</em> file:

<dependency>
    <groupId>org.openimaj</groupId>
    <artifactId>core-image</artifactId>
    <version>1.3.5</version>
</dependency>

You will find the latest release here.

4.1. Loading an Image

To load an image, use ImageUtilities.readMBF() method:

MBFImage image = ImageUtilities.readMBF(new File("path/to/your/image.jpg"));

MBF stands for the multiband floating-point image (RGB in this example, but it’s not the only way to represent colors).

4.2. Editing an Image

To draw the rectangle, we need to define its shape which is polygon consisting of 4 points (top left, bottom left, bottom right, top right):

Point2d tl = new Point2dImpl(10, 10);
Point2d bl = new Point2dImpl(10, image.getHeight() - 10);
Point2d br = new Point2dImpl(image.getWidth() - 10, image.getHeight() - 10);
Point2d tr = new Point2dImpl(image.getWidth() - 10, 10);
Polygon polygon = new Polygon(Arrays.asList(tl, bl, br, tr));

As you might have noticed, in image processing Y-axis is reversed. After defining the shape, we need to draw it:

image.drawPolygon(polygon, 4, new Float[] { 0f, 0f, 255.0f });

Drawing method takes 3 arguments: shape, line thickness and RGB channel values represented by Float array.

4.3. Displaying an Image

We need to use DisplayUtilities:

DisplayUtilities.display(image);

5. TwelveMonkeys ImageIO

The TwelveMonkeys ImageIO library is intended as an extension to the Java ImageIO API, with support for a larger number of formats.

Most of the time, the code will look the same as the built-in Java code, but it will function with additional image formats, after adding the necessary dependencies.

By default, Java supports only these five formats for images: JPEG, PNG, BMP, WEBMP, GIF.

If we attempt to work with an image file in a different format, our application will not be able to read it and will throw a NullPointerException when accessing the BufferedImage variable.

TwelveMonkeys adds supports for the following formats: PNM, PSD, TIFF, HDR, IFF, PCX, PICT, SGI, TGA, ICNS, ICO, CUR, Thumbs.db, SVG, WMF.

To work with images in a specific format, we need to add the corresponding dependency, such as imageio-jpeg or imageio-tiff.

You can find the full list of dependencies in the TwelveMonkeys documentation.

Let’s create an example that reads a .ico image. The code will look the same as the AWT section, except we will open a different image:

String imagePath = "path/to/your/image.ico";
BufferedImage myPicture = ImageIO.read(new File(imagePath));

For this example to work, we need to add the TwelveMonkeys dependency that contains support for .ico images, which is the imageio-bmp dependency, along with the imageio-core dependency:

<dependency>
    <groupId>com.twelvemonkeys.imageio</groupId>
    <artifactId>imageio-bmp</artifactId>
    <version>3.3.2</version>
</dependency>
<dependency>
    <groupId>com.twelvemonkeys.imageio</groupId>
    <artifactId>imageio-core</artifactId>
    <version>3.3.2</version>
</dependency>

And this is all! The built-in ImageIO Java API loads the plugins automatically at runtime. Now our project will work with .ico images as well.

6. Summary

You have been introduced to 4 libraries that can help you work with images. Going further, you might want to look for some image processing algorithms, like extracting edges, enhancing contrast, using filters or face detection.

For those purposes, it might be better to start learning ImageJ or OpenIMAJ. Both are easy to include in a project and are much more powerful than AWT regarding image processing.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.

 

Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)