clever way to change icon color?

Howdy,

In a tree control, I have a (large) family of icons which are a black shape on a transparent background. Depending on
various conditions determined while running, I have to change the color of the icon. Is there a clever way to do
this without drawing new bitmaps? Maybe something with bit operations on the bitmap or else a mask?

TIA,
Danny

If you use wx.DrawBitmap with a mono bitmap, the text colors are used,
which you can use to draw in arbitrary colors. It has to be a depth 1
bitmap, though, which you can have if you use a mask, so I don't know
how you could do it with true transparency.

If you're drawing on a solid color, you can just set the text
background to the same as the regular background.

···

On 1/12/07, Danny Shevitz <shevitz@lanl.gov> wrote:

Howdy,

In a tree control, I have a (large) family of icons which are a black shape
on a transparent background. Depending on
various conditions determined while running, I have to change the color of
the icon. Is there a clever way to do
this without drawing new bitmaps? Maybe something with bit operations on
the bitmap or else a mask?

TIA,
Danny

... And if I'd read more carefully, I'd have noticed that you were
using these in a wx.TreeCtrl, which requires an image list, so you
aren't doing your own drawing. You can create the new icons at
runtime, so you don't need to ship all the colors of all the bitmaps,
but you'll still need to have all of them in the image list, you can't
do clever drawing tricks.

···

On 1/12/07, Chris Mellon <arkanes@gmail.com> wrote:

On 1/12/07, Danny Shevitz <shevitz@lanl.gov> wrote:
> Howdy,
>
> In a tree control, I have a (large) family of icons which are a black shape
> on a transparent background. Depending on
> various conditions determined while running, I have to change the color of
> the icon. Is there a clever way to do
> this without drawing new bitmaps? Maybe something with bit operations on
> the bitmap or else a mask?
>
> TIA,
> Danny
>

If you use wx.DrawBitmap with a mono bitmap, the text colors are used,
which you can use to draw in arbitrary colors. It has to be a depth 1
bitmap, though, which you can have if you use a mask, so I don't know
how you could do it with true transparency.

If you're drawing on a solid color, you can just set the text
background to the same as the regular background.

thanks for the response. I forgot to mention that I'm using img2py to have the icons in
code. img2py auto generates the get***Data methods, so I have a representation of
the bitmap in ascii (I don't need to compress). I really don't understand the format.
I guess I was hoping it was possible
to get the data, use a regular expression to extract the data component and then with some
clever bit operations, such as drawing in white and then (red&image, ...), get what I want.

I know it was a stretch, but I was hoping... If I understood the asci format better in the
img2py data piece maybe it would still be possible.

D

···

At 01:15 PM 1/12/2007 -0600, you wrote:

On 1/12/07, Chris Mellon <arkanes@gmail.com> wrote:

On 1/12/07, Danny Shevitz <shevitz@lanl.gov> wrote:
> Howdy,
>
> In a tree control, I have a (large) family of icons which are a black shape
> on a transparent background. Depending on
> various conditions determined while running, I have to change the color of
> the icon. Is there a clever way to do
> this without drawing new bitmaps? Maybe something with bit operations on
> the bitmap or else a mask?
>
> TIA,
> Danny
>

If you use wx.DrawBitmap with a mono bitmap, the text colors are used,
which you can use to draw in arbitrary colors. It has to be a depth 1
bitmap, though, which you can have if you use a mask, so I don't know
how you could do it with true transparency.

If you're drawing on a solid color, you can just set the text
background to the same as the regular background.

... And if I'd read more carefully, I'd have noticed that you were
using these in a wx.TreeCtrl, which requires an image list, so you
aren't doing your own drawing. You can create the new icons at
runtime, so you don't need to ship all the colors of all the bitmaps,
but you'll still need to have all of them in the image list, you can't
do clever drawing tricks.

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Danny Shevitz wrote:

thanks for the response. I forgot to mention that I'm using img2py to have the icons in
code. img2py auto generates the get***Data methods, so I have a representation of
the bitmap in ascii (I don't need to compress). I really don't understand the format.

The embedded format is the same as a PNG file.

I guess I was hoping it was possible
to get the data, use a regular expression to extract the data component and then with some
clever bit operations, such as drawing in white and then (red&image, ...), get what I want.

I know it was a stretch, but I was hoping... If I understood the asci format better in the
img2py data piece maybe it would still be possible.

Take a look at the new raw bitmap access demo in 2.8. This will let you, for example, iterate through the pixels of an existing image, and write out the modified pixel data to another image.

You can also do something similar with pre 2.8 versions with wx.Image, either by using GetRed/GetGreen/GetBlue and SetRGB methods, or you can get the image data as a string of RGB bytes and manipulate it. Then you just need to convert it back to a wx.Bitmap.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!