简体   繁体   中英

How to combine vertical and horizontal lineargradientbrush in Image.OpacityMask

I have Image. I want make blur edge for Image. I can add on Image.OpacityMask only one LinearGradientBrush and make only Horizontal or only Vertical blurred edge:

<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>

How to combine vertical and horizontal lineargradientbrush?

One way would be to stack two rectangles on top of the image ...

<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>

I don't think you can apply multiple brushes within a fill / mask.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM