尝试更改图像中透明部分的颜色

时间:2016-12-24 07:04:23

标签: c# xaml uwp

您好我正在尝试更改图像透明部分的颜色。请参阅图像 实际上我使用它作为网格中的背景图像是否有任何方法可以改变该图像的外部部分的颜色,即透明部分,并且不应该对不透明的图像的主要部分应用效果。点击&#34 ; FwdBtn" image outer主图像的透明部分应该改变。 XAML

 <Grid.Background>

            <ImageBrush x:Name="imgbg" ImageSource="Assets/LearnColor/bg.png"
                        />
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition x:Name="rowDefHeaderPanel" Height="1*"/>
            <RowDefinition x:Name="rowDefContentPanel" Height="3*"/>
            <RowDefinition x:Name="rowDefFooterPanel" Height="1*"/>
        </Grid.RowDefinitions>
        <RelativePanel x:Name="Headerpanel" Grid.Row="0" Margin="0,0,0,0">
            <Image x:Name="prevBtn" 
            Source="Assets/LearnColor/Button/btn_previous_arrow.png"
               RelativePanel.AlignLeftWithPanel="True"
               Margin="0,33,-246,23"
               Tapped="BckImgChng" HorizontalAlignment="Right" Width="88" d:LayoutOverrides="Height"/>
            <Image x:Name="FwdBtn"
            Source="Assets/LearnColor/Button/btn_next_arrow.png"              
               Height="88"
               RelativePanel.AlignRightWithPanel="True"
               Margin="-152,0,250,-121"
               Tapped="FwdImgChng" VerticalAlignment="Bottom" d:LayoutOverrides="HorizontalAlignment"/>
            <Image x:Name="Header" 
            Source="Assets/LearnColor/Header/_0000_header_0.png" Width="440"
               RelativePanel.AlignVerticalCenterWithPanel="True"                 
               Margin="0,-39,-814,-62" HorizontalAlignment="Right"               
               >
                <Image.Triggers>
                    <EventTrigger RoutedEvent="Image.Loaded">
                        <BeginStoryboard>
                            <Storyboard x:Name="Blinkopr">
                                <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" AutoReverse="True" Duration="0:0:0.9" RepeatBehavior="Forever"
                                                 Storyboard.TargetName="Header"/>
                            </Storyboard>
                        </BeginStoryboard>

                    </EventTrigger>
                </Image.Triggers>
            </Image>
            <TextBlock x:Name="HeaderName"
                Text="Yellow"
                       FontFamily="Font/BALLOON.TTF#BALLOON"
              RelativePanel.AlignVerticalCenterWithPanel="True"                 
               Margin="543,13,-273,7" Foreground="White" FontSize="25" FontStyle="Normal" FontWeight="ExtraBold" />

        </RelativePanel>

C#代码

private void FwdImgChng(object sender, TappedRoutedEventArgs e)
        {
            //if (currentIndex == 11)
            //{ return; }
            currentIndex++;
            if (currentIndex > 10)
            {
                currentIndex = 10;
                return;
            }

            Header.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Header/_0000_header_" + currentIndex + ".png"));
            image.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Object/ob_" + currentIndex + "_0.png"));
            prevObjBtn.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Button/prev" + currentIndex + ".png"));
            fwdObjBtn.Source = new BitmapImage(new Uri("ms-appx:///Assets/LearnColor/Button/next" + currentIndex + ".png"));
            HeaderName.Text = Headername[currentIndex];            
            objNameWritten.Text = objnamewritten[currentIndex];
            objNameWritten.Foreground = new SolidColorBrush(HColorname[currentIndex]);
            mediaElement1.Source = new Uri("ms-appx:///Assets/LearnColor/Objectnamesmp3/C" + currentIndex + ".mp3");
            //mediaElement1.AutoPlay = true;


        }

图像enter image description here

1 个答案:

答案 0 :(得分:1)

将你的网格放在另一个控件中并为其设置背景,你可以使用你喜欢的任何控件,例如我在这里使用了另一个网格:

<Grid Background="#c0c0c0">
<!-- Your grid here-->
</Grid>