• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

HSV gradient

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there.
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.

Any pointers?



Edit: Okay, now this is extra sad. This post comes up in spot #1 in a Google search for java gradient hsb OR hsv OR hsl ...
 
Steven Sørensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
URGENT!!! plz sir send teh codez god bless

Or "bump" or something.

I'm guessing this means there isn't a nice built-in way to create these gradients...
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://faq.javaranch.com/java/PatienceIsAVirtue
(I'll ignore the mistyped words since that was obviously meant as a joke )
 
Marshal
Posts: 80652
476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It was 1½ weeks before he asked for a bump, Rob.

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.
 
Rob Spoor
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Steven Sørensen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Steven Sørensen wrote: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.


Bumping is allowed after 24 hours, but the "URGENT" was what I wanted to address. I just posted the wrong link.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an example of an HSV gradient track I wrote using the relationships between RGB and HSV found here: Wiki (HSV and HSL)

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is my best solution :

Override GradientPaint (easy part) to HSVGradientPaint
copy paste/ GradientPaintContext into HSVGradientPaint (easy part)

there is an ugly code from sun that I can't get rid of (if someone has a deep knowledge on how to work on raster ...)

and replace the interp array filling (in the construcor) with one that matches HSV color.

here is the master piece, use this function to fill the "interp" array instead of the original code.


and BTW I would realllllllly like to find a better solution.

eric

(ps: attachement does not work, here is a copy paste of the whole solution )
 
reply
    Bookmark Topic Watch Topic
  • New Topic