今天我要实现在图片上剪切我们想要的图形。

首先新建一个WPF应用程序。

我们在图片上实现剪切,那一定要用到Image控件了。用到Image的剪切属性Clip。

下面我们先截一个椭圆。

<Grid>
        <Image Source="tulips.jpg" Width="300" Height="200" Stretch="Fill">
            <Image.Clip>
                <EllipseGeometry Center="150,100"  RadiusX="120" RadiusY="90"/>
            </Image.Clip>
        </Image>
    </Grid>

效果如图:

MSDN 教学视频 WPF10(图片剪切) 

image.Clip下有6个可画的图形。
1、CombinedGeometry  表示由两个 System.Windows.Media.Geometry 对象组合定义的二维几何形状。

2、GeometryGroup 表示由其他 System.Windows.Media.Geometry 对象组成的复合几何图形。

3、LineGeometry 表示线条的几何图形。

4、PathGeometry

指定用于生成此动画输出值的几何图形。这是一个依赖项属性。

返回值:
用于生成此动画输出值的路径。默认值为 null。

5、RectangleGeometry  描述二维矩形。

6、StreamGeometry

定义几何形状,并使用 System.Windows.Media.StreamGeometryContext 进行描述。此几何图形是 System.Windows.Media.PathGeometry 的轻量替代图形:它不支持数据绑定、动画或修改。

下面我们用PathGeomitry来画。

150,30" IsClosed="True">
                                <LineSegment Point="60,180" />
                                <LineSegment Point="240,180"/>
                            </PathFigure>
                        </PathFigureCollection>
                    </PathGeometry.Figures>
                </PathGeometry>
            </Image.Clip>
        </Image>

这里用到IsClosed=”True”是图形封闭起来。如图:

MSDN 教学视频 WPF10(图片剪切)

相关文章:

  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-08-21
  • 2022-12-23
  • 2021-10-02
  • 2021-11-29
猜你喜欢
  • 2021-04-21
  • 2021-11-02
  • 2022-12-23
  • 2021-12-12
  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案