如何在 silverlight/WP7(颜色蒙版)中更改图像的颜色? [英] How can I change the color of an image in silverlight/WP7 (Color Mask)?

查看:27
本文介绍了如何在 silverlight/WP7(颜色蒙版)中更改图像的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有透明背景和黑色前景的 png 的切换按钮.如果选择了按钮,那么我希望图像的黑色更改为用户选择的颜色.有没有办法在 Silverlight 和/或 wp7 中做到这一点?

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?

例如:

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

MyImage.png 具有透明背景和黑色前景.用户的首选颜色是红色.当按钮打开时,我希望图像的黑色前景变为红色.

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.

推荐答案

我会尝试使用 OpacityMask 方法.基本上它应该是这样的:

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.

这篇关于如何在 silverlight/WP7(颜色蒙版)中更改图像的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆