Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change Foreground Color of Image in View

I have a horizontal StackPanel of an Image and TextBlock. What I need to accomplish is changing the foreground of both to a certain color. I can easily change the TextBlock with the Foreground property, but I am not sure how to do this with an Image. The image is just a basic app icon.

<StackPanel Orientation="Horizontal">
    <Image Source="/Assets/Icons/appbar.book.perspective.png" Width="50" Height="50" Margin="-8,0,-6,0"/>
    <TextBlock Text="BOOK" VerticalAlignment="Center" Foreground="Blue"/>
</StackPanel>
like image 783
Matthew Avatar asked Jan 08 '14 05:01

Matthew


People also ask

How do you change the foreground color in an image?

To change the foreground or background color, click its swatch and then select a new color from the Color Picker. To change the foreground or background color to a color you already have in your image, click the swatch. The cursor becomes an eyedropper that you can use to sample a color in the image.

Which color is used for foreground color?

The foreground controls what color your brush or pencil will be, while the background color erases any added color and replaces it with the background color, which is white by default. If you erase on a transparent layer, however, whatever you erase will become transparent instead.

How do I change the color of a image in Swift?

If you are setting the image for a button, just go to attributes inspector and change the button type to system. Then set the image and change the tint color. The color of the image will change.


3 Answers

BitmapIcon is helpful for what you can use instead:

<BitmapIcon Width="20" Height="20" Foreground="Red" UriSource="ms-appx:///Assets/Resources/YourImage.png" />

That's my way...:)

like image 167
bravohex Avatar answered Oct 27 '22 00:10

bravohex


Instead of having an ImageViewer and Textblock use Grid and Textblock. Give the background of grid as desired image source.Place a Textblock inside the grid.And assign the text to the TextBlock inside the grid. You can accomplish your task.

like image 42
Praveen Avatar answered Oct 27 '22 00:10

Praveen


Do you want to change image background color then take image with transparent backround and set code as below

    <StackPanel Orientation="Horizontal">
        <Grid Background="Blue" Width="50" Height="50" Margin="-8,0,-6,0">
            <Image Source="/Assets/Icons/appbar.book.perspective.png" />
        </Grid>
        <TextBlock Text="BOOK" VerticalAlignment="Center" Foreground="Blue"/>
    </StackPanel>
like image 30
Heena Avatar answered Oct 27 '22 00:10

Heena