Skip to content

Create a composite image from combining two images using blend modes in Java.

Notifications You must be signed in to change notification settings

aabalke33/blend-modes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 

Repository files navigation

blend-modes

Create a composite image from combining two images using blend modes in native Java.

The Blend Modes package enables blending different images, or image layers, by means of blend modes. These modes are commonly found in graphics programs like Adobe Photoshop or GIMP.

Blending through blend modes allows to mix images in a variety of ways. This package currently supports the following 18 blend modes:

  • Normal (BlendMode.normal())
  • Darken (BlendMode.darken())
  • Multiply (BlendMode.multiply())
  • Color Burn (BlendMode.colorBurn())
  • Linear Burn (BlendMode.linearBurn())
  • Lighten (BlendMode.lighten())
  • Screen (BlendMode.screen())
  • Color Dodge (BlendMode.colorDodge())
  • Addition / Linear Dodge (BlendMode.addition())
  • Overlay (BlendMode.overlay())
  • Soft Light (BlendMode.softLight())
  • Hard Light (BlendMode.hardLight())
  • Vivid Light (BlendMode.vividLight())
  • Linear Light (BlendMode.linearLight())
  • Difference (BlendMode.difference())
  • Subtract (BlendMode.subtract())
  • Divide (BlendMode.divide())

The intensity of blending can be controlled by means of an opacity parameter that is passed into the functions. See Usage for more information.

This package does not require JavaFX. It is built using the Java AWT API only.

Youtube Video Breakdown

Usage

The blend mode methods take image data expressed as a BufferedImage. An example is provided below for a standard method of creating and inputting BufferedImage parameters.

Input Methods are overloaded. Allowing for method calls with opacity inputs and without. If an opacity value is not inputted, it is assumed to be 1 (100%).

// With Opacity Value
BufferedImage image = BlendMode.screen(bg, fg, opacity);

// Without Opacity Value
BufferedImage image = BlendMode.screen(bg, fg);

Important Considerations

  1. Foreground and Background images have to be the same size.
  2. Has to be 8 Bit per Channel Image.
  3. Opacity is a beta feature. It is not completely accurate in certain blend modes.

Example

import BlendMode.BlendMode;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class Example {
    public static void main(String[] args) throws IOException {

        // Set Variable Names
        BufferedImage bg = ImageIO.read(new File("background.jpg"));
        BufferedImage fg = ImageIO.read(new File("foreground.jpg"));
        double opacity = .5;

        // Create Composite
        BufferedImage image = BlendMode.screen(bg, fg, opacity);

        // Export Composite
        ImageIO.write(image, "jpg", new File("output.jpg"));
    }
}

Roadmap

  • Fix Opacity Feature to work with all blend modes properly
  • Provide solution for different image sizes
  • Support 16bit and 24bit images

Images

bg fg normal darken multiply colorburn linearburn lighten screen colordodge addition overlay softlight hardlight vividlight linearlight difference subtract divide

About

Create a composite image from combining two images using blend modes in Java.

Topics

Resources

Stars

Watchers

Forks

Languages