Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the color of an image in silverlight/WP7 (Color Mask)?

I have a toggle button with a png that has a transparent background and a black foreground. If the button is selected then I want the black color of the image to change to a color chosen by the user. Is there a way to do this in Silverlight and/or wp7?

So for example:

<ToggleButton>
    <Image Source="MyImage.png" />
</ToggleButton>

MyImage.png has a transparent background and a black foreground. The user's preferred color is red. When the button is toggled on I want the black foreground of the image to turn red.

like image 954
Micah Avatar asked Oct 16 '10 20:10

Micah


1 Answers

I would try OpacityMask approach. Basicaly it should look something like this:

<Rectangle Fill="Red">
  <Rectangle.OpacityMask>
    <ImageBrush ImageSource="MyImage.png"/>
  </Rectangle.OpacityMask>
</Rectangle>

by changing rectangle's fill property you would get different colored image.

like image 165
Denis Avatar answered Oct 18 '22 04:10

Denis