Colour Swapping

Here’s a Java example of the colour-swapping code I intend to implement:

Image src;
ImageFilter colourFilter;
Image img;

/**
* init()
*/
private void init(){
    try {
        src = ImageIO.read(new File(dir));
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    colourFilter = new RedBlueSwapFilter();
    // apply filter to new image
    img = createImage(new FilteredImageSource(src.getSource(), colourFilter));
}

/**
* CLASS
* RedBlueSwapFilter
*/
class RedBlueSwapFilter extends RGBImageFilter {
    public RedBlueSwapFilter() {
        canFilterIndexColorModel = true;
    }

    public int filterRGB(int x, int y, int rgb) {
        return ((rgb & 0xff00ff00)
            | ((rgb & 0xff0000) >> 16)
            | ((rgb & 0xff) << 16));
    }
}

And the results it produces:

example1
example2
 
 
 
TRP

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s