how to grayscale the24 bit bitmap

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
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.



 Maybe this article can help you

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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.
image_nationAuthor Commented:
No friends..
You haven't tell me Grayscaling of 24 bit BMP.
You told @ 8bit BMP thats easy.
plz send ur views @ it
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Yes he have, because one char has 8bit and 3*8 = 24bit !!
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.
I mean 256.
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
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.


no more

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.