James dean wrote:
Do i have to create an index pallette. How do i do that?. Or, Can i not
just make an ordinary 8pp pixel format without this indexed
problem......
This question is off-topic, but I'll try to answer it with respect to C#.
When you convert an image from 32 bits per pixel to 8 bits per pixel, in
most cases some information will necessarily be lost, because 8 bits can
only represent 256 distinct colours. A typical photo has thousands of
distinct colours, and even antialiased diagrams or text often have
hundreds. It is conceivable that the 8 bits could be broken up into fields
for red, green, and blue, but this would leave only 2 bits (4 distinct
values) per component, which is inadequate for most images.
For this reason, it's more typical to create an index palette, where each
8-bit value is an index into a very carefully-chosen table of valid colour
values. There are then two essential problems with converting an image from
a 32 bpp to an 8 bpp format: choosing the colors in the palette, and then
converting the image to use only these colors. This process is called color
reduction, and the two steps are closely intertwined. These are both
difficult problems on which a great deal of research has been done,
involving perceptual similarity of colours, dithering algorithms, and so
on. In short, you don't want to do this yourself.
Luckily, there are a number of alternatives. If the image is static, reduce
it beforehand in a tool like Adobe Photoshop or Paint Shop Pro. For
example, in Photoshop you'd do this:
1. Open the image.
2. Choose Image menu->Mode->Indexed Color.
3. Select one of the Local options from the Palette drop-down list, enter
256 in the Colors field, and select a Dither option. You may want to check
the preview box and experiment with the Dither and Palette options.
4. Hit OK when satisfied.
If you need to color reduce an image at runtime, and your quality needs are
low or your images have few colors, you may be able to use the Image class
from the System.Drawing namespace, which wraps the GDI+ API. From Q319061
(
http://support.microsoft.com/default...N-US;Q319061):
After GDI+ modifies an Image and then writes an image to a file by
using the GIF encoder, GDI+ writes the file by using a halftone palette
to which the Image object's bits have been color reduced.
There are also more sophisticated commercial libraries for high-quality
color reduction. Here are a few links I found, currently each about $500
(not to be interpreted as endorsements by Microsoft):
LEADTOOLS Raster Imaging Pro for .NET
http://www.leadtools.com/SDK/dotNET/RIP-for.NET.htm
Aurigma Graphics Mill 3.1 for .NET
http://www.aurigma.com/Products/GraphicsMilldotNET/
Victor Image Processing Library
http://www.catenary.com/prodsumm/vicsum.html
Here's a related question at Borland developer support:
http://community.borland.com/article...,15972,00.html
I hope this helps.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no
rights.