?
Solved

how to grayscale the24 bit bitmap

Posted on 2003-03-13
11
Medium Priority
?
307 Views
Last Modified: 2013-12-03
Hello experts,
I have 1 question.
I have displayed 24 bit bitmap on client area.
now I have to convert it grayscale image how I do?
because there is no palette for 24 bit as know
how to do it.
please anybody can give me some solution for this.
thank you
0
Comment
Question by:image_nation
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 12

Accepted Solution

by:
williamcampbell earned 100 total points
ID: 8129500

image

 Maybe this article can help you

http://codeguru.earthweb.com/bitmap/grayscale.shtml
0
 

Expert Comment

by:martinhoge
ID: 8135985

Get buffer with image data.
   For example:

     void *ImageData;

   In this data are pixels stored in BGR format. Memory can see as "BGRBGRBGRBGRBGRBGR....", all you need to do
is read every byte and calculate their average value:

   unsigned char r,g,b, back;
   __int16 temp;

   for (i=0;i<end of data;i+=3)
       {
       // first block
       memcpy(&b, (void *)((DWORD)ImageData),1);
       memcpy(&g, (void *)((DWORD)ImageData + 1),1);
       memcpy(&r, (void *)((DWORD)ImageData + 1),1);

       // second block
       temp = (r + g + b) / 3;
       back = (unsigned char) temp;

       // third block
       memcpy((void *)((DWORD)ImageData),&b,1);
       memcpy((void *)((DWORD)ImageData + 1),&g,1);
       memcpy((void *)((DWORD)ImageData + 1),&r,1);
       }

First block read RGB of a pixel. (see BGR direction)
Second is for calculate average value and store again
into back ( unsigned int )
Third is for putting pixel back to memory

BUT: !!!
  Now I'm tired even I don't know if there are "&r" or "r" in memory functions

  Don't forget, that one scanline must be flush for 4 byte blocks.
0
 

Author Comment

by:image_nation
ID: 8141288
No friends..
You haven't tell me Grayscaling of 24 bit BMP.
You told @ 8bit BMP thats easy.
plz send ur views @ it
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:jufo03
ID: 8143815
Yes he have, because one char has 8bit and 3*8 = 24bit !!
0
 
LVL 1

Expert Comment

by:keitha1
ID: 8162620
You can't do a 24 bit grayscale. There is only an 8-bit DAC on the output. Plus, gray, by definition, has the red, green, and blue values the same. each component can only range from 0 to 255. By my calculations, that's only 255 different shades of gray.
0
 
LVL 1

Expert Comment

by:keitha1
ID: 8162625
I mean 256.
0
 

Expert Comment

by:martinhoge
ID: 8164938
That's nice, but in 24 bit TrueColor you can do,
I think, 768 types of gray. I've write that program.

I've got on your mind this:
1.  0  0  0
2.  1  1  1
3.  2  2  2
...
255. 255 255 255

, but another choice is:

1. 0 0 0
2. 0 0 1
3. 0 1 1
4. 1 1 1
5. 1 1 2
6. 1 2 2

.. and so on
0
 
LVL 1

Expert Comment

by:keitha1
ID: 8167078
Well, if you find a way to get more than 256 values out of 8 bits please share it with the world. By definition, gray has each color component set to the same value and each component is only 8 bits.

R,G,B
0,0,0
1,1,1
2,2,2
...
192,192,192
...
254,254,254
255,255,255

no more

0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question