Sign in to follow this  

Convert Grayscale Bitmap

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have spent about a week roaming this forum and the rest of the internet looking for a way to render a color bitmap in grayscale with directx 9.0. After a lot of searching i found out it is done by basically doing a palette swap. So here is my problem. I load the bitmap in GDI and obtain the palette information as long as it is a 256 color bitmap or less. I then take the average and use that to create a new palette where each color has a value equal to the average. I set the peFlags to 255, to take care of the alpha channel. I then delete the GDI version and load the bitmap into a surface (LoadSurfaceFromFile). After which i call: pDevice->SetPaletteEntries(500,m_peGray); pDevice->SetCurrentTexturePalette(500); Where pDevice is my LPDIRECT3DDEVICE9. The 500 doesnt really matter i tried tons of unsigned ints. And i have tried running both of those calls before the Surface call, i also tried running these commands in the Render Loop. The program compiles correctly, and neither of those functions return an error, but the picture simply renders as a color image when i present it. I present using the backbuffer: pDevice->UpdateSurface(m_pSurface, &m_SourceRect, pRenderSurface, &m_DestPoint); Where pRenderSurface is a pointer to the BackBuffer. All i want to do is load a bitmap convert it to grayscale and use it as a background, if anyone has any ideas or can offer any help, please let me know, thank you for anything you can offer, have a great day.

Share this post


Link to post
Share on other sites
Read documentation of

D3DXColorAdjustSaturation() Function

in D3DX sdk!


it says,

The grayscale color is computed as:

r = g = b = 0.2125*r + 0.7154*g + 0.0721*b;


You will need to do this for every pixel of your bitmap and store the computed new value per pixel in a new empty 8-bit but of same dimensions bitmap.

Share this post


Link to post
Share on other sites

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this