This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Suggestions on colour convertor program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Suggestions on colour convertor program" Watch "Suggestions on colour convertor program" New topic
Author

Suggestions on colour convertor program

Mikpo Siru
Ranch Hand

Joined: Apr 09, 2009
Posts: 54
Hi,

I want to write a program that maps the colours of a user-selected image to the closest matching colours in a given set. Here is the basic operation:

-User opens an image using the program
-The program checks the colour of each pixel in the image
-For each pixel, the program chooses the closest matching colour from a set of eight colours (red, green, blue, cyan, magenta, yellow, white, black)
-The program makes a new image from the 8 colours
-The program displays the new image

I have GUI programming experience in Java, but it's been some months since my last project (this is abit of a refresher).

I am looking for is suggestions on how to proceed. For example, useful classes, good methods of implementation (should I go through pixel by pixel?), etc.

Thanks
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

Take the easy way ;)

-- Load your image
-- Create a IndexColorModel with the required colors
-- Construct a BufferedImage the same size as your image, of TYPE_BYTE_INDEXED and the index color model
-- Obtain the Graphics reference of the second image
-- Draw the first image to the second image
-- Profit


luck, db
There are no new questions, but there may be new answers.
Mikpo Siru
Ranch Hand

Joined: Apr 09, 2009
Posts: 54
Hi,

Thanks for the reply. I have started a sister thread specifically on making an IndexColorModel: http://www.coderanch.com/t/504292/GUI/java/Creating-IndexColorModel-Colours.

I will post problems I have with the overall convterter program in this thread.

Regards.
Mikpo Siru
Ranch Hand

Joined: Apr 09, 2009
Posts: 54
Thanks Darryl, I have a working program now.

For reference, here is the part of the program that does the conversion:


IndexColorModel colourModel was generated using Darryl's code snippet in http://www.coderanch.com/t/504292/GUI/java/Creating-IndexColorModel-Colours:

Regards.
 
jQuery in Action, 2nd edition
 
subject: Suggestions on colour convertor program