File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Suggestions on colour convertor program" Watch "Suggestions on colour convertor program" New topic

Suggestions on colour convertor program

Mikpo Siru
Ranch Hand

Joined: Apr 09, 2009
Posts: 54

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.

Darryl Burke

Joined: May 03, 2008
Posts: 5115

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

Thanks for the reply. I have started a sister thread specifically on making an IndexColorModel:

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

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

I agree. Here's the link:
subject: Suggestions on colour convertor program
It's not a secret anymore!