Changing the color of an image when a button is pressed
up vote
-1
down vote
favorite
I have a Button that contains an Image to act as the icon.
The image is white with a transparent background, and I would like to tint it when the button is pressed.
The color of the tint can be changed at runtime so I cannot have multiple versions of the same image to swap them.
I tried overlaying a Rectangle using the image itself as the opacity mask, but it seems that resizing the opacity mask does not use any antialiasing so the result is really poor.
What is the correct way to approach this in WPF?
wpf xaml
add a comment |
up vote
-1
down vote
favorite
I have a Button that contains an Image to act as the icon.
The image is white with a transparent background, and I would like to tint it when the button is pressed.
The color of the tint can be changed at runtime so I cannot have multiple versions of the same image to swap them.
I tried overlaying a Rectangle using the image itself as the opacity mask, but it seems that resizing the opacity mask does not use any antialiasing so the result is really poor.
What is the correct way to approach this in WPF?
wpf xaml
2
There are many ways to achieve what you want. The probably "best" or "correct" way would be to not use an image at all. Use a vector icon in a Path element instead and change its Fill Brush.
– Clemens
12 hours ago
Thanks @Clemens , if that's the only way I'll try experimenting with that. That being said, it looks a bit weird to me that this is not included... I'd think it were easier.
– Michele Ippolito
9 hours ago
You may perhaps use the Image in an ImageBrush as OpacityMask of a Rectangle where you change the Fill Brush.
– Clemens
9 hours ago
I tried that too, but as I said in the question the antialiasing on that is terrible and the result is too blocky to be usable.
– Michele Ippolito
9 hours ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a Button that contains an Image to act as the icon.
The image is white with a transparent background, and I would like to tint it when the button is pressed.
The color of the tint can be changed at runtime so I cannot have multiple versions of the same image to swap them.
I tried overlaying a Rectangle using the image itself as the opacity mask, but it seems that resizing the opacity mask does not use any antialiasing so the result is really poor.
What is the correct way to approach this in WPF?
wpf xaml
I have a Button that contains an Image to act as the icon.
The image is white with a transparent background, and I would like to tint it when the button is pressed.
The color of the tint can be changed at runtime so I cannot have multiple versions of the same image to swap them.
I tried overlaying a Rectangle using the image itself as the opacity mask, but it seems that resizing the opacity mask does not use any antialiasing so the result is really poor.
What is the correct way to approach this in WPF?
wpf xaml
wpf xaml
asked 13 hours ago
Michele Ippolito
41139
41139
2
There are many ways to achieve what you want. The probably "best" or "correct" way would be to not use an image at all. Use a vector icon in a Path element instead and change its Fill Brush.
– Clemens
12 hours ago
Thanks @Clemens , if that's the only way I'll try experimenting with that. That being said, it looks a bit weird to me that this is not included... I'd think it were easier.
– Michele Ippolito
9 hours ago
You may perhaps use the Image in an ImageBrush as OpacityMask of a Rectangle where you change the Fill Brush.
– Clemens
9 hours ago
I tried that too, but as I said in the question the antialiasing on that is terrible and the result is too blocky to be usable.
– Michele Ippolito
9 hours ago
add a comment |
2
There are many ways to achieve what you want. The probably "best" or "correct" way would be to not use an image at all. Use a vector icon in a Path element instead and change its Fill Brush.
– Clemens
12 hours ago
Thanks @Clemens , if that's the only way I'll try experimenting with that. That being said, it looks a bit weird to me that this is not included... I'd think it were easier.
– Michele Ippolito
9 hours ago
You may perhaps use the Image in an ImageBrush as OpacityMask of a Rectangle where you change the Fill Brush.
– Clemens
9 hours ago
I tried that too, but as I said in the question the antialiasing on that is terrible and the result is too blocky to be usable.
– Michele Ippolito
9 hours ago
2
2
There are many ways to achieve what you want. The probably "best" or "correct" way would be to not use an image at all. Use a vector icon in a Path element instead and change its Fill Brush.
– Clemens
12 hours ago
There are many ways to achieve what you want. The probably "best" or "correct" way would be to not use an image at all. Use a vector icon in a Path element instead and change its Fill Brush.
– Clemens
12 hours ago
Thanks @Clemens , if that's the only way I'll try experimenting with that. That being said, it looks a bit weird to me that this is not included... I'd think it were easier.
– Michele Ippolito
9 hours ago
Thanks @Clemens , if that's the only way I'll try experimenting with that. That being said, it looks a bit weird to me that this is not included... I'd think it were easier.
– Michele Ippolito
9 hours ago
You may perhaps use the Image in an ImageBrush as OpacityMask of a Rectangle where you change the Fill Brush.
– Clemens
9 hours ago
You may perhaps use the Image in an ImageBrush as OpacityMask of a Rectangle where you change the Fill Brush.
– Clemens
9 hours ago
I tried that too, but as I said in the question the antialiasing on that is terrible and the result is too blocky to be usable.
– Michele Ippolito
9 hours ago
I tried that too, but as I said in the question the antialiasing on that is terrible and the result is too blocky to be usable.
– Michele Ippolito
9 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371984%2fchanging-the-color-of-an-image-when-a-button-is-pressed%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
There are many ways to achieve what you want. The probably "best" or "correct" way would be to not use an image at all. Use a vector icon in a Path element instead and change its Fill Brush.
– Clemens
12 hours ago
Thanks @Clemens , if that's the only way I'll try experimenting with that. That being said, it looks a bit weird to me that this is not included... I'd think it were easier.
– Michele Ippolito
9 hours ago
You may perhaps use the Image in an ImageBrush as OpacityMask of a Rectangle where you change the Fill Brush.
– Clemens
9 hours ago
I tried that too, but as I said in the question the antialiasing on that is terrible and the result is too blocky to be usable.
– Michele Ippolito
9 hours ago