This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Number of colors in an Image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Number of colors in an Image " Watch "Number of colors in an Image " New topic

Number of colors in an Image

John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215

I have a program that extracts the colors used in an image. The image is created by me using MSPaint (please take a look at the attached picture). I believe that the program should show atmost 7 unique colors. But i get many results. The code is given below:

Why does this happen?

[Thumbnail for circle.jpg]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41124
You'll probably find that the extra colors occur around the circles perimeters. Most drawing programs don't just paint a single line of black pixels, they add interpolated pixels to the left and right of the line in order to create a smooth appearance.

So there'll probably be lots of colors that are halfway between black and whatever color happens to occur on one side of the line. I'm sure high-end drawing apps have a way of preventing this; not sure about Paint, though.

Ping & DNS - my free Android networking tools app
It is sorta covered in the JavaRanch Style Guide.
subject: Number of colors in an Image
Similar Threads
Logical operation on Image
How do i find out what color a certain pixel is?
Extracting Pixel Data From Fonts
Image Animation...
why do my white and black pixels come out red and grey?