Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Suggestions on colour convertor program

 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mikpo Siru
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic