Java Color Invert invert(Color color)

Here you can find the source of invert(Color color)

Description

invert

License

LGPL

Declaration

public static Color invert(Color color) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.awt.Color;

public class Main {
    public static Color invert(Color color) {
        return new Color(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue());
    }//from  w w w.  ja  v a2  s.c o m

    public static String invert(String color) {
        return colorToHexString(invert(hexStringToColor(color)));
    }

    public static String colorToHexString(Color color) {
        String hexString = Integer.toHexString(color.getRGB() & 0x00ffffff);

        while (hexString.length() < 6) {
            hexString = "0" + hexString;
        }

        return "#" + hexString;
    }

    public static Color hexStringToColor(String hexString) {
        return Color.decode(hexString);
    }
}

Related

  1. invert(Color c)
  2. invert(Color color)
  3. invert(Color color)
  4. invert(Color colour)
  5. invertColor(Color c)