This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm having a bit of trouble finding a way to generate an HSV gradient...
sRGB and Linear RGB gradients are simple enough, as they're predefined in the java.awt.MultipleGradientPaint class and whatnot. But I can't for the life of me find a way to use the HSV (or HSB or HSL) colorspace to blend two colors. (And frustratingly, java.awt.color.ColorSpace isn't implemented out-of-the-box for common colorspaces. Arg.)
RGB gradient? Easy enough, it's implied:
But the HSV colorspace? There certainly doesn't seem to be any obvious way to to use it. Am I missing something right in front of me?
The best I could dig up with Google was this page: http://users.erols.com/ziring/java-samp-jgd.html It's pretty good, and the source code is very clean, but it's doesn't use the java.awt.Paint interface. I'm not sure how to retrofit it with Graphics2D compatibility.
Everything else I saw on Google was trivial algorithms to convert one colorspace to another. Not helpful.
Campbell Ritchie wrote:It was 1½ weeks before he asked for a bump, Rob.
You're right, it should have been Ease Up. My bad.
Joined: Apr 01, 2009
Yeah, I know bumping isn't considered good form, but I've lurked* here for a while and seen it accepted, so I thought I'd give it a shot.
(*Unintentionally: Google often correctly suggests this place for the solutions to a quite a number of problems I've run into. So kudos for that.)
Campbell Ritchie wrote:You can convert HSB to RGB with methods in the Color class; you might be able to use those to pass H, S and B values to Color objects and use those objects. Another Color link here.
I have tried that, but actually it's just for converting values into the Color class's RGB storage form. (I checked the source code to be sure!) The GradientPaint class is what does the blending dirty work.
Just yesterday I started playing around with the Processing framework/library/API/whathaveyou. It's pretty great and has a really easy-to-use (read: made-for-n00bs) color handling that can easily blend on in HSB space.
Although I'm a bit disappointed that there seems to be no out-of-the-box Java way of doing this, I'll be using the Processing methods from now on, which are entirely sufficient.