Link
Skip to main content

Image processing in Java

JDeli provides a Java image processing API that applies transformation operations — such as scaling, rotation, blurring, and sharpening — to image files or in-memory BufferedImage objects. Operations are defined using ImageProcessingOperations, can be chained in any order, and are applied in a single pass via JDeli.convert() or JDeli.process().

Add JDeli to your project via Maven or Gradle, or see using JDeli with Java modules.

Process an image file

Pass an ImageProcessingOperations object to JDeli.convert() to apply transformations during conversion. JDeli can also convert between image formats in the same call.

JDeli.convert(File inputFile, File outputFile, ImageProcessingOperations operations);

View Javadoc on JDeli.convert

JDeli.convert() also accepts InputStream/OutputStream and byte[] — see the code examples below.

Process a BufferedImage

JDeli provides two ways to apply operations to a BufferedImage directly, without file I/O:

Using JDeli.process() — use when you want to keep image processing separate from the JDeli pipeline:

image = JDeli.process(ImageProcessingOperations operations, BufferedImage image);

View Javadoc on JDeli.process

Using ImageProcessingOperations.apply() — use when you already have an ImageProcessingOperations instance and want to apply it directly:

image = operations.apply(BufferedImage image);

ImageProcessingOperations class

ImageProcessingOperations provides built-in transformations and an ImageOperation interface for custom operations. Operations execute in the order they are added.

Create an instance and pass it to JDeli.process() or JDeli.convert().

Example 1 — Create a set of processing operations

ImageProcessingOperations operations = new ImageProcessingOperations();
operations.scale(1f);
operations.custom(new MyCustomProcess());
operations.rotate(90); // degrees

Example 2 — Chain operations using the builder pattern

ImageProcessingOperations operations = new ImageProcessingOperations()
    .scale(1f)
    .custom(new MyCustomProcess())
    .rotate(90);

Example 3 — Undo and redo operations

operations.undo(); // remove last operation added
operations.redo(); // re-add last operation removed

Example 4 — Implement a custom operation

private class MyCustomImageOperation implements ImageOperation {

    private Object myArgs;

    public MyCustomImageOperations(Object myArgs) {
        this.myArgs = myArgs;
    }

    @Override
    public BufferedImage apply(BufferedImage image) {
        // process code here
        return image;
    }
}

ImageProcessingOperations operations =
    new ImageProcessingOperations(new MyCustomImageOperation(myArgs));

View Javadoc on process package

Frequently Asked Questions

What image processing operations does JDeli support?

JDeli supports scaling, rotation, blurring, sharpening, and custom operations via the ImageOperation interface. Multiple operations can be chained on a single ImageProcessingOperations instance.

What is the difference between JDeli.process() and JDeli.convert() for image processing?

JDeli.process() applies operations to a BufferedImage in memory and returns a BufferedImage — no format conversion occurs. JDeli.convert() applies operations and writes the result to a file, stream, or byte array, optionally changing the image format at the same time.

Does JDeli apply image processing operations in the order they are added?

Yes. Operations are applied sequentially in the order they were added to the ImageProcessingOperations instance.

Can I undo or redo operations in ImageProcessingOperations?

Yes. Call operations.undo() to remove the last added operation and operations.redo() to re-add it.

Can I add a custom image processing operation in JDeli?

Yes. Implement the ImageOperation interface and pass an instance to operations.custom() or directly to the ImageProcessingOperations constructor.


Why JDeli?

  • Support image formats such as AVIF, HEIC and JPEG XL that are not supported in Java.
  • Process images up to 3x faster than ImageIO and alternative Java image libraries.
  • Prevent JVM crashes caused by native code in other image libraries such as ImageIO.
  • Handle JPEG, PNG, TIFF image file formats fully in Java.
  • Keep your Image files secure as JDeli makes no calls to any external system or third party library.

Learn more about JDeli

Start Your Free Trial