473,545 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11132
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
7251
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. Specifically, I have a problem with this portion in the WHERE clause: DATEADD(Day,tblMyEventTableName.ReminderDays, @DateNow) Between...
1
4451
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 System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding(); now i am using enc.GetString(value) and the value retured is one byte less if the size of the byte...
11
1838
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 (if you name program as "transform"), transform 1000, for 1000 seconds...
2
2645
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 the same width and height as the previous 8bpp data. Is it possible that i can just clone this data but i can't really as i am not allowed to create...
4
1717
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; public byte Green; public byte Red; public byte transparent; }
3
6084
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 tell how to do it? ------ Thanks
8
20257
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 , double, triple byte etc). I need to convert to upper case only those characters which has got upper case. ie if an user enter bot english and...
8
47856
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 that image in grayscale format.How do i do that.It still saves in true color format. -i used picturebox1.image.save() method -i tried to convert...
0
5041
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 get the db to translate to UTF-8 for non technical reasons. So I have a string coming back with the character œ (ISO value 156). this character...
0
7478
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7410
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7668
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7437
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5343
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4960
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3466
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.