Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I reduce the number of colors used in an image

Status
Not open for further replies.

gecsealexandru

Programmer
Aug 18, 2005
1
RO
I am trying to make asimple image processing application and I want to be able to reducethe number of colors used. All that Ihave found is some code for changing the color depth.

I need a procedure:

ReduceColors(Image1.Picture.Bitmap, no_of_colors);

Does somebody know a procedure for this task?

10x
 
I'm not particularly sure I can give you a procedure, but perhaps I can give you a hint for what to do:

Let's say you have 65535 colors in your bitmap and you want to go to 256 colors. If we look, colors are generally represented in powers of 2 related to bytes stored.

2^8 = 256
2^16 = 65535
2^24 = 16777216 (or 16m colors)

I wouldn't make "no_of_colors" be any different than what I have listed, because it would be out of standard for graphics.

You should be able to relationally plot the same color sets in each type, and then mathematically take away additional information for each byte representing a color in the image. Perhaps just truncating the detailed data in your larger color set so it is roughly equivalent to the same data in the 256 color set.

That's as far as I would go with what I know. I would find out how colors are stored in each group, find a few equivalent representations and then do some testing and then eyeball what you get. Would it work to simply truncate or would you set a equidistant range with the 256 color representation as the median?

Again hope this helps you out.
 
hi,

thise code if far away in my memory but, i have done something similar in the past...(for bitmap)

the idea is that a bitmap as a palette that contain all color used in the image... what u can do is to change one palette entry by another color.. i dont think this will change the bitmap size.. but this will reduce the number of color in the image...

take a look at Tbitmap and maybe "palette" in the help file and ull probably find some usefull exemples, i've just checked in d5 help file and found pre-fab code exemples...

hopes this will help you

jb

 
it wont reduce the size in a bitmap, but it would in a jpeg i believe, so he could just convert it using delphi's native JPEG encoding (D5 and up).

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
Great Delphi Websites faq102-5352
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top