WPF 通过透明度遮罩和变换制作倒影效果

 

倒影效果

image

代码

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<Canvas
  xmlns=“http://schemas.microsoft.com/client/2007“
  xmlns:x=“http://schemas.microsoft.com/winfx/2006/xaml“>
 
  <!– The object to reflect. –>
  <Image Source=“gear_large.png“
    Canvas.Left=“75“ Canvas.Top=“20“>
  </Image>
 
  <!– The reflection. –>
  <Image Source=“gear_large.png”
    Canvas.Left=“75“ Canvas.Top=“228”
    Opacity=“0.75”>
    <Image.RenderTransform>
      <ScaleTransform ScaleY=“-0.75“ />
    </Image.RenderTransform>
    <Image.OpacityMask>
      <LinearGradientBrush StartPoint=“0.5,0.0“ EndPoint=“0.5,1.0“>
        <GradientStop Offset=“0.0“ Color=“#00000000“ />
        <GradientStop Offset=“1.0“ Color=“#FF000000“ />
      </LinearGradientBrush>
    </Image.OpacityMask>
  </Image>
 
</Canvas>

 

更加复杂的应用

image

参考

https://blogs.msdn.microsoft.com/wpfedevcon/2007/01/05/use-transforms-and-opacity-masks-to-create-a-reflection-in-wpfe/

Opacity Masks Overview

posted @   霍旭东  阅读(1569)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
点击右上角即可分享
微信分享提示