473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to convert from 32argb to 8bpp correctly

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......

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #1
2 11110
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.
Nov 17 '05 #2
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.
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
11
by: Bore Biko | last post by:
Dear, I have function that transform time from secconds to string formated as dd:hh:mm:ss (days:hours:minutes:seconds), but it doesent work correctly... Here s code compiled with gcc it goes...
2
by: James Dean | last post by:
I can display an 8bpp indexed bitmap correctly but when i tried to convert this to 32ARGB then it didn't display properly at all. I am just wondering how i can display the same 24bpp image at the...
4
by: James Dean | last post by:
I am trying to directly set the pixels in a 32ARGB image but for some reason i am not setting them correctly. I have a struct 4 bytes in size... public struct PixelData { public byte Blue;...
3
by: Sharon | last post by:
I have a buffer of byte that contains a raw data of a 1 byte-per-pixel image data. I need to convert this buffer to a Bitmap of Format32bppArgb and to a Bitmap of Format24bppRgb. Can anybody...
8
by: csanjith | last post by:
Hi, i have a situaion where i need to convert the characters entered in an text field to upper case using C. The configuration id utf8 environment in which user can enter any character (single ,...
8
by: platinumhimani | last post by:
-How to convert any image(8,16,24,32 or 64-bit) to 8-bit grayscale -i have tried to convert a 24-bit image to grayscale using setpixel and getpixel functions, in vb.net but i am unable to save...
0
by: deloford | last post by:
Hi This is going to be a question for anyone who is an expert in C# Text Encoding. My situation is this: I have a Sybase database which is firing back ISO-8559 encoded strings. I am unable to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.