如何在Image.OpacityMask中组合垂直和水平lineargradientbrush

时间:2013-10-30 10:19:29

标签: c# silverlight windows-phone-7 windows-phone-8

我有图像。 我想为图像制作模糊边缘。 我可以在Image.OpacityMask上添加一个LinearGradientBrush并仅使其成为水平或仅垂直模糊边缘:

<Image Height="300" Width="450" Name="oldImg" Source="/untitled.jpg">
 <Image.OpacityMask>
  <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
   <GradientStop Offset="0" Color="Transparent"></GradientStop>
   <GradientStop Offset=".3" Color="Black"></GradientStop>
   <GradientStop Offset=".7" Color="Black"></GradientStop>
   <GradientStop Offset="1" Color="Transparent"></GradientStop>
  </LinearGradientBrush>
 </Image.OpacityMask>
</Image>

如何组合纵向和横向lineargradientbrush?

1 个答案:

答案 0 :(得分:2)

一种方法是在图像顶部堆叠两个矩形......

<Grid>
<Image Height="300" Width="450" Name="oldImg" Source="/untitled.jpg"></Image>
 <Rectangle >
  <Rectangle.Fill>
    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
     <GradientStop Offset="0" Color="White"></GradientStop>
     <GradientStop Offset=".3" Color="Transparent"></GradientStop>
     <GradientStop Offset=".7" Color="Transparent"></GradientStop>
     <GradientStop Offset="1" Color="White"></GradientStop>
    </LinearGradientBrush>
  </Rectangle.Fill>
  </Rectangle>
 <Rectangle>
  <Rectangle.Fill>
    <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
     <GradientStop Offset="0" Color="White"></GradientStop>
     <GradientStop Offset=".3" Color="Transparent"></GradientStop>
     <GradientStop Offset=".7" Color="Transparent"></GradientStop>
     <GradientStop Offset="1" Color="White"></GradientStop>
    </LinearGradientBrush>
  </Rectangle.Fill>
  </Rectangle>
</Grid>

我认为您不能在填充/蒙版中应用多个画笔。