• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Suggestions on colour convertor program

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for the reply. I have started a sister thread specifically on making an IndexColorModel: https://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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 https://coderanch.com/t/504292/GUI/java/Creating-IndexColorModel-Colours:

Regards.
 
The moustache of a titan! The ad of a flea:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic