Colorizing Bitmaps

I've been enjoying working on the new, more, umm, "modern" looking pTravelAlarm lately. One of the fun things about opening up development on new versions of applications is that you tend to get a flood of suggestions, and since development is open, you tend to implement them ;-)

A repeated request is to allow the user to change the color of the text on the screen. This would, of course, be trivially easy if we were using text exclusively, but a lot of what you see is actually bitmaps.

In actuality, mapping a color in a bitmap to another color isn't all that hard either - although certainly more difficult that simply setting the color of a piece of text, since it involves modifying the actual RGB values in the bitmap. Luckily I had a piece of code lying around from Phone Today, which has the need to map its icons to the Windows Mobile Today Screen theme color.

The code to do the colorizing is presented below for those who might have the need to do something like this. Basically the LoadAndColorizeBitmap method does the actual loading of the bitmap resource as well as mapping one particular color to another.

All of the bitmaps which will have their color changed are saved using a particular color (yellow, in my case). When the Windows Mobile application starts and loads the required bitmaps, it calls LoadAndColorizeBitmap, passing in the resource id and the requested color. LoadAndColorizeBitmap loads the bitmap and changes the color, returning a normal HBITMAP handle to the caller. No further work is required (except, of course, to call DeleteObject when done with the bitmap).

I only had the need to map yellow to something else, so you'll see #define statements for the red, green and blue values of the source color, but the function could be generalized if necessary.

The code

/Entries/Code/WindowsMobile | permanent link

 

 Site Search


 Categories
» Entries (86)
  » Code (1)
    » WindowsMobile (1)
  » M3U2iTunes (2)
  » Mac (35)
  » MediaCenter (6)
  » Programming (3)
  » StoryGrinder (4)
  » Venom (1)
  » Windows (1)
  » WindowsMobile (5)
  » iPod-iTunes (7)

 Archives
» November 2006 (1)
» October 2006 (2)
» September 2006 (3)
» August 2006 (4)
» July 2006 (2)
» June 2006 (3)
» May 2006 (2)
» April 2006 (3)
» March 2006 (3)
» February 2006 (4)
» January 2006 (4)
» December 2005 (2)
» November 2005 (4)
» October 2005 (2)
» September 2005 (4)
» August 2005 (3)
» July 2005 (4)
» June 2005 (2)
» May 2005 (6)
» April 2005 (3)
» March 2005 (6)
» February 2005 (7)
» January 2005 (4)
» November 2004 (4)
» July 2004 (2)
» June 2004 (2)

 Downloads  

StoryGrinder


Version: 1.0RC1
Download page

BSD Fortune Dashboard Widget


Version: 1.4
Download

M3U2iTunes


Version: 1.0
Download M3U2iTunes



Copyright © 2006 otherslikeyou.com Inc.
All trademarks and copyrights on this page are owned by their respective owners.