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?










share|improve this question


















  • 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















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?










share|improve this question


















  • 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













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules