Changing colors in a 24-bit bitmap?

Started by
3 comments, last by azjerei 19 years, 11 months ago
Is it possible to change, on the fly via code, the colors in a 24-bit bitmap? I am not loading them using DDraw. My aim is to be able to, for example, color a character''s bitmap red when he or she is hurt. With color it red I mean changing the hue to more red.
Advertisement
The short answer is... you can''t. 24bpp images are not palettized (I''m assuming that''s what you mean?) and therefore you can''t change their colors on the fly.

However, nothing''s stopping you from writing your own recoloring algorithm to redden slightly every pixel or whatnot. If the sprite you want to recolor isn''t too big, you probably won''t have any noticeable performance hit with a per-pixel recoloring algorithm.

I''m not sure what you mean by "I am not loading them using DDraw." What API are you using? GDI? SDL? Textured quad in DirectX/OpenGL? A more complete answer to your question would be difficult to provide without knowing what you''re working with exactly.
I dunno... no special API is being used, so I guess it''s the standard windows stuff *shrug*

Still a n00b at this all though... :-/
dont quite understand what you mean.i assume you will load the bitmap into a chunk of memory either DirectX surface or just normal array.and when the object is low on health.you wanna it to appear to be "redder",in other word increase red channel of all the pixels in the bitmap.if that is the case,there are several way of doing it.

start from the easiest,you can manually shift the colour of the bitmap to red in Photoshop.and render the red one if it is low on health otherwise draw the normal one.this can be done with just a few extra line of code.the problem with it is that it increases the memory reqirement.imagine if there is 10MB of bitmap,after doing so the size of bitmap increase to its double,coz there is one more same size bitmap need to be loaded.

also you can shift the colour by software pixel by pixel.just add some extra value to the red channel of each pixel before rendering,but considering it is done pixel by pixel.it is gonna be pretty slow.
Are you trying to turn the whole character red? if so, blending the texture with the vertex color may acheive the desired effect.. Although just turning things red when they''re getting damage may look odd.. I would suggest using a 2 or 3 texture sets if possible, one for healthy, one for hurt, another for really beat up

Just some possible alternative ideas

This topic is closed to new replies.

Advertisement