We help IT Professionals succeed at work.

ColorModel

InteractiveMind
on
Medium Priority
203 Views
Last Modified: 2010-03-31
Can someone give me a quick run through of why you'd want to use the ColorModel class - and why it's useful ?

The MemoryImageSource class accepts a ColorModel as a parameter to one of it's constructors — what effect will this have?

Thanks.
Comment
Watch Question

Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
It handles mapping pixel value into rgba colour components.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Top Expert 2006

Author

Commented:
But what does that actually mean?
Are the pixels not stored in a way based on RGB ?  (a << 24)|(r << 16)|(g << 8)|(b)  [or something like that]
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
no they are merely stored as numbers. The ColorModel takes that value and returns the colour components.
Top Expert 2006

Author

Commented:
So, in the case of the MemoryImageSource: is there a default ColorModel that is used (if one is not specified) ?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
Whats the data you're using, and how do you want it mapped?
Siva Prasanna KumarPrincipal Solutions Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
Siva Prasanna KumarPrincipal Solutions Architect
CERTIFIED EXPERT
Top Expert 2006
Commented:
http://www.java2s.com/ExampleCode/2D-Graphics-GUI/Color-Model.htm

oops i didn't knew you & objects wee in conversation.
Mayank SPrincipal Technologist
CERTIFIED EXPERT
Commented:
>> is there a default ColorModel that is used (if one is not specified) ?

Yes, it uses the default RGB colormodel.
Top Expert 2006

Author

Commented:
I've got an IndexColorModel (produced using an algorithm I got elsewhere), which I pass to my MemoryImageSource constructor.

I then have an array called 'envMap' containing numbers ranging from 0-255. My rendering algorithm calculates which value to use (based on some unrelated criteria), and then passes that integer (from the envMap array) to the MemoryImageSource (or rather, sets the appropriate pixel within the pixel array to that integer).

So, the IndexColorModel in this case, would that just be using the given integer (from the envMap) to calculate the RGBA color to use?
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
Thats correct, using the map you specify.
Each index would correspond to a different rgb value

Top Expert 2006

Author

Commented:
Okay, thanks very much.
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
no worries :)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.