Skip to content

Instantly share code, notes, and snippets.

@idr-solutions
Created June 2, 2025 09:53
Show Gist options
  • Save idr-solutions/b8b75b1009114d15b7cc61139c26051a to your computer and use it in GitHub Desktop.
Save idr-solutions/b8b75b1009114d15b7cc61139c26051a to your computer and use it in GitHub Desktop.
invert colors | color inversion | Invert image colors

Image Color Inversion in Java

You can use JDeli to achieve image color inversion in Java. JDeli is an enterprise-level Java image library that makes it easy to read, write, convert, manipulate and process HEIC and other image file formats in Java.

This class uses the provided image and returns an inverted image containing negative argb values image. This makes the image appear inverted.

Example in Java to invert colors of an image

ImageProcessingOperations operations = new ImageProcessingOperations();

// You can chain several operations here such as scale, blur, etc
operations.invertColors(); 
        
// Apply the operations to a BufferedImage
BufferedImage modifiedImage = operations.apply(BufferedImage originalImage);

Additional Code Examples

Process and convert between image formats using the following code examples:

Using File

File inputFile = new File("path/to/file");
File outputFile = new File("path/to/output-inverted-file");
JDeli.convert(inputFile, outputFile, operations);

Using InputStream and OutputSteam

final InputStream inputStream = new FileInputStream(inputFile);
final OutputStream outputStream = new FileOutputStream(outputFile);
final String outputFormat = "format"; // format of the output file eg. png, jpeg,...;
JDeli.convert(inputStream, outputStream, outputFormat, operations);

Using byte[]

byte[] inputData = Files.readAllBytes(Paths.get("/path/to/file"));
final String outputFormat = "format"; // format of the output file eg. png, jpeg,...;
byte[] outputData = JDeli.convert(inputData, outputFormat, operations);

View Javadoc on the invert colors operation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment