0

In JavaScript I have used the JQuery plugin xcolor, which is a fantastic little tool for working with colors. It has color string parsers, all the color space conversion methods, a few color filters, and my favorite, a gradient generator (see $.xcolor.gradientlevel()).

I'm looking for something similar in Java. Other bonuses would be falsecolor routines (convert a number to a color - a powerful one would have parameters like max/min cutoff and log vs. linear scales) and color schemes (like red -> orange -> yellow -> green gradient generator).

Are there any free libraries out there that can do some of these things in Java or is this something I have to roll myself? I haven't found much from my googling except for some things in AWT, but I need it to be generic because I'm not working with any Java GUI stuff at all.

Tony R
  • 11,224
  • 23
  • 76
  • 101
  • 1
    I don't know what you have to do, but you should be able to use java.awt.Color also on in a server side component, even without a GUI. – Simone Gianni Aug 01 '12 at 02:20
  • @SimoneGianni Thanks, I know about Color but it doesn't do everything I described in the question. – Tony R Aug 01 '12 at 02:46
  • I was supposing that "except for some things in AWT" was referring to libraries or other stuff using java.awt.Color. – Simone Gianni Aug 01 '12 at 03:27
  • `java.awt.Color` is a cute but very limited container for RGB values. I need more advanced stuff but don't want to hack something out of AWT because I'm not using it. – Tony R Aug 04 '12 at 05:03
  • FYI if you're not into jQuery (there are better things these days), I ported xcolor to remove the jQuery dependency: https://github.com/fresheneesz/xolor – B T Jan 17 '17 at 02:45

2 Answers2

1

Java's Color class should work fine:

Color.brighter()
Color.darker()

Gradients:

http://docs.oracle.com/javase/6/docs/api/java/awt/GradientPaint.html

Generating gradients programmatically?

Hue Saturation: Color.getHSBColor(hue, saturation, brightness)

Community
  • 1
  • 1
Alex W
  • 37,233
  • 13
  • 109
  • 109
  • Does it have something for false colors? (log/linear etc.) – Tony R Aug 01 '12 at 02:45
  • @TonyR That is something you could easily implement with HSB. Just change the hue slowly from 0.0 to 1.0 while also raising and lowering the brightness. – Alex W Aug 01 '12 at 02:57
  • Thanks, it sounds like I'll have to write most of these routines myself. `Color.brighter()` applies an "arbitrary scale factor" to the color. So it's not good enough, but I guess I knew that or I wouldn't have asked the question =P. The other stuff is way too AWT-specific (including trashgod's links...), I just want a simple generic color library, even if it uses `java.awt.Color`. Thanks for the answer! – Tony R Aug 04 '12 at 04:38
1

I have not tried using it. But I came across apache commons imaging library & it seems interesting

http://commons.apache.org/proper/commons-imaging/

Water
  • 127
  • 8