[源码下载]

背水一战 Windows 10 (12) - 绘图: Shape, Path

作者:webabcd

介绍
背水一战 Windows 10 之 绘图

  • Shape - 图形
  • Path - 路径

示例
1、演示“Shape”相关知识点
Drawing/Shape.xaml

<Page
x:Class="Windows10.Drawing.Shape"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Drawing"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <!--
Windows.UI.Xaml.Shapes.Shape - 图形
注:对于封闭图形的 stroke 来说,其是绘制在控件内部的
--> <!--
Line - 画直线
-->
<!--
X1, Y1 - 直线起点坐标
X2, Y2 - 直线终点坐标
-->
<Line X1="0" Y1="0" X2="300" Y2="100" Stroke="Blue" StrokeThickness="3" /> <!--
Rectangle - 画矩形
-->
<!--
Width - 矩形宽
Height - 矩形高
-->
<Rectangle Width="200" Height="50" Fill="Red" Stroke="Yellow" StrokeThickness="3" /> <!--
Polyline - 画折线(即多条连接起来的直线)
-->
<!--
Points - 折线的每个点的坐标
-->
<Polyline Points="10,100 50,10 100,100" Stroke="Green" StrokeThickness="3" /> <!--
Polygon - 画多边形
-->
<!--
Points - 多边形的每个点的坐标
-->
<Polygon Points="50,50 100,50 300,100 200,100 100,200" Fill="Yellow" Stroke="Red" StrokeThickness="6" /> <!--
Ellipse - 画椭圆
-->
<!--
Width - 椭圆宽
Height - 椭圆高
-->
<Ellipse Width="100" Height="50" Fill="Orange" Stroke="Red" StrokeThickness="6" /> <!--
矩形或椭圆在不设置宽和高时,可以指定其 Stretch 用以指定其相对于其容器的拉伸方式
Stretch - 拉伸方式(Windows.UI.Xaml.Media.Stretch 枚举)
Fill - 充满容器,不保留长宽比
None - 不做任何处理,如果图片比容器大,则多出的部分被剪裁
Uniform - 等比缩放到容器(默认值)
UniformToFill - 充满容器,且保留长宽比,多出的部分被剪裁
-->
<Grid Width="200" Height="100" HorizontalAlignment="Left" Background="Black">
<Ellipse Fill="Orange" Stroke="Red" StrokeThickness="6" Stretch="UniformToFill" />
</Grid> </StackPanel>
</Grid>
</Page>

2、演示“Path”相关知识点
Drawing/Path.xaml

<Page
x:Class="Windows10.Drawing.Path"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Drawing"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10" HorizontalAlignment="Left"> <!--
Windows.UI.Xaml.Shapes.Path - 路径,以下演示如何通过 Path 绘制图形
Data - 要绘制的 Windows.UI.Xaml.Media.Geometry 数据(Geometry 有很多派生类,后面会一一介绍,其实都不太常用,最常用的就是直接画路径,见最后面)
--> <Path Fill="Yellow" Stroke="Blue" StrokeThickness="6" Margin="5">
<Path.Data>
<!--
EllipseGeometry - 椭圆
Center - 原点坐标
RadiusX - X轴半径
RadiusY - Y轴半径
-->
<EllipseGeometry Center="50,25" RadiusX="50" RadiusY="25" />
</Path.Data>
</Path> <Path Fill="Yellow" Stroke="Blue" StrokeThickness="6" Margin="5">
<Path.Data>
<!--
RectangleGeometry - 矩形
Rect - 左上角点的坐标,矩形宽,矩形高
-->
<RectangleGeometry Rect="100,0,100,50" />
</Path.Data>
</Path> <Path Stroke="Blue" StrokeThickness="6" Margin="5">
<Path.Data>
<!--
LineGeometry - 线
StartPoint - 起点坐标
EndPoint - 终点坐标
-->
<LineGeometry StartPoint="200,0" EndPoint="300,50" />
</Path.Data>
</Path> <Path Stroke="Blue" StrokeThickness="6" Margin="5">
<Path.Data>
<!--
PathGeometry - 路径,一个可能由弧、曲线、椭圆、直线、矩形组成的复杂图形
-->
<PathGeometry>
<PathGeometry.Figures>
<!--
StartPoint - 起点坐标
-->
<PathFigure StartPoint="300,0">
<PathFigure.Segments>
<!--
Path 的 Segment 集合
-->
<PathSegmentCollection>
<!--
LineSegment - 单一线段
PolyLineSegment - 线段集合
ArcSegment - 弧(椭圆的一部分)
BezierSegment - 两点之间的一条三次贝塞尔曲线
QuadraticBezierSegment - 两点之间的一条二次贝塞尔曲线
PolyBezierSegment - 一条或多条三次贝塞尔曲线
PolyQuadraticBezierSegment - 一条或多条二次贝塞尔曲线
-->
<!--
ArcSegment
Size - 弧的 X 轴和 Y 轴半径
Point - 该 Segment 的终点坐标,即下一个 Segment 的起点坐标
SweepDirection - 绘制方向(Clockwise - 顺时针绘制;Counterclockwise - 逆时针绘制)
RotationAngle - 椭圆围绕 x 轴旋转的角度(这个需要自己写几个示例去理解)
IsLargeArc - 绘制的弧大于 180 度则为 true,反之则为 false(只读)
-->
<ArcSegment Size="100,25" Point="400,50" />
<!--
LineSegment
Point - 该 Segment 的终点坐标,即下一个 Segment 的起点坐标
-->
<LineSegment Point="500,100" />
</PathSegmentCollection>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path> <Path Fill="Yellow" Stroke="Blue" StrokeThickness="6" Margin="5">
<Path.Data>
<!--
本例演示 GeometryGroup 的 EvenOdd 填充规则
GeometryGroup - 由一个或多个 Geometry 组成
FillRule - 填充规则(System.Windows.Media.FillRule 枚举)
EvenOdd - 确定一个点是否位于填充区域内的规则,具体方法是从该点沿任意方向画一条无限长的射线,然后计算该射线在给定形状中因交叉而形成的路径段数。如果该数为奇数,则点在内部;如果为偶数,则点在外部。
Nonzero - 确定一个点是否位于填充区域内的规则,具体方法是从该点沿任意方向画一条无限长的射线,然后检查形状段与该射线的交点。从零开始计数,每当线段从左向右穿过该射线时加 1,而每当路径段从右向左穿过该射线时减 1。计算交点的数目后,如果结果为零,则说明该点位于路径外部。否则,它位于路径内部。
-->
<GeometryGroup FillRule="EvenOdd">
<LineGeometry StartPoint="200,0" EndPoint="300,100" />
<EllipseGeometry Center="250,50" RadiusX="50" RadiusY="50" />
<RectangleGeometry Rect="200, 0, 100, 100" />
</GeometryGroup>
</Path.Data>
</Path> <Path Fill="Yellow" Stroke="Blue" StrokeThickness="6" Margin="5">
<Path.Data>
<!--
本例演示 GeometryGroup 的 Nonzero 填充规则
GeometryGroup - 由一个或多个 Geometry 组成
FillRule - 填充规则(System.Windows.Media.FillRule 枚举)
EvenOdd - 确定一个点是否位于填充区域内的规则,具体方法是从该点沿任意方向画一条无限长的射线,然后计算该射线在给定形状中因交叉而形成的路径段数。如果该数为奇数,则点在内部;如果为偶数,则点在外部。
Nonzero - 确定一个点是否位于填充区域内的规则,具体方法是从该点沿任意方向画一条无限长的射线,然后检查形状段与该射线的交点。从零开始计数,每当线段从左向右穿过该射线时加 1,而每当路径段从右向左穿过该射线时减 1。计算交点的数目后,如果结果为零,则说明该点位于路径外部。否则,它位于路径内部。
-->
<GeometryGroup FillRule="Nonzero">
<LineGeometry StartPoint="200,0" EndPoint="300,100" />
<EllipseGeometry Center="250,50" RadiusX="50" RadiusY="50" />
<RectangleGeometry Rect="200, 0, 100, 100" />
</GeometryGroup>
</Path.Data>
</Path> <!--
演示 Path 最常用的用法,即直接画
1、直接指定 Geometry 数据
2、一般都是要借助工具,最流行的是“Metro Studio”,其 4.0 以上的版本可以在设计完后显示对应的 Geometry 代码
-->
<Path Fill="Black" Stroke="White" StrokeThickness="6" Data="M 10,100 L 100,100 100,50 Z M 10,10 100,10 100,40 Z" Margin="5" /> </StackPanel>
</Grid>
</Page>

OK
[源码下载]

背水一战 Windows 10 (12) - 绘图: Shape, Path的更多相关文章

  1. 背水一战 Windows 10 (13) - 绘图: Stroke, Brush

    [源码下载] 背水一战 Windows 10 (13) - 绘图: Stroke, Brush 作者:webabcd 介绍背水一战 Windows 10 之 绘图 Stroke - 笔划 Brush ...

  2. 重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush

    原文:重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush [源码下载] 重新想象 Windows 8 Store Apps ...

  3. 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧

    [源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...

  4. 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox

    [源码下载] 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox 作者:webabcd ...

  5. 背水一战 Windows 10 (26) - XAML: x:DeferLoadStrategy, x:Null

    [源码下载] 背水一战 Windows 10 (26) - XAML: x:DeferLoadStrategy, x:Null 作者:webabcd 介绍背水一战 Windows 10 之 XAML ...

  6. 背水一战 Windows 10 (20) - 绑定: DataContextChanged, UpdateSourceTrigger, 对绑定的数据做自定义转换

    [源码下载] 背水一战 Windows 10 (20) - 绑定: DataContextChanged, UpdateSourceTrigger, 对绑定的数据做自定义转换 作者:webabcd 介 ...

  7. 背水一战 Windows 10 (19) - 绑定: TemplateBinding 绑定, 与 RelativeSource 绑定, 与 StaticResource 绑定

    [源码下载] 背水一战 Windows 10 (19) - 绑定: TemplateBinding 绑定, 与 RelativeSource 绑定, 与 StaticResource 绑定 作者:we ...

  8. 背水一战 Windows 10 (18) - 绑定: 与 Element 绑定, 与 Indexer 绑定, TargetNullValue, FallbackValue

    [源码下载] 背水一战 Windows 10 (18) - 绑定: 与 Element 绑定, 与 Indexer 绑定, TargetNullValue, FallbackValue 作者:weba ...

  9. 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果)

    [源码下载] 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果) 作者:webabcd 介绍背水一战 Windows 10 之 动画 ThemeTrans ...

随机推荐

  1. Redis系列(四)-低成本高可用方案设计

    关于Redis高可用方案,看到较多的是keepalived.zookeeper方案. keepalived是主备模式,意味着总有一台浪费着.zookeeper工作量成本偏高. 本文主要介绍下使用官方s ...

  2. Node.js返回JSONP

    在使用JQuery的Ajax从服务器请求数据或者向服务器发送数据时常常会遇到跨域无法请求的错误,常用的解决办法就是在Ajax中使用JSONP.基于安全性考虑,浏览器会存在同源策略,然而<scri ...

  3. Fiddler调式使用知多少(一)深入研究

    Fiddler调式使用(一)深入研究 阅读目录 Fiddler的基本概念 如何安装Fiddler 了解下Fiddler用户界面 理解不同图标和颜色的含义 web session的常用的快捷键 了解we ...

  4. Screeps ———— A MMO Strategy Sandbox Game for Programmers

    At the beginning, let's see three of this game's captures. Yes, As what you see in these pictures, y ...

  5. Windows无法安装到这个磁盘。请确保在计算机的BIOS菜单中启用了磁盘控制器

    今天一朋友问我这个问题,呃,以前我也遇到过,但忘记记录了,这次就记录一下吧,就懒得打字了,图片里面很清楚了 不说点什么的话是不是太水了O(∩_∩)O~,好吧扩充一下: Windows无法安装到这个磁盘 ...

  6. [转]浏览器退出之后php还会继续执行么?

    原文链接:http://www.cnblogs.com/yjf512/p/5362025.html 前提:这里说的是典型的lnmp结构,nginx+php-fpm的模式 如果我有个php程序执行地非常 ...

  7. 前端学PHP之命名空间

    × 目录 [1]定义 [2]多命名空间 [3]名称解析[4]访问内部元素[5]全局空间[6]别名和导入 前面的话 从广义上来说,命名空间是一种封装事物的方法.在很多地方都可以见到这种抽象概念.例如,在 ...

  8. Android获取短信验证码

    Android开发中关于短息验证码的设计层出不穷,越来越多的应用为了更好的提高软件的安全性,开始使用通过服务器向用户发送验证码的方式,来保护用户个人信息的安全性.无论是用户注册时的信息验证还是当用户发 ...

  9. Dijkstra算法优先队列实现与Bellman_Ford队列实现的理解

    /* Dijkstra算法用优先队列来实现,实现了每一条边最多遍历一次. 要知道,我们从队列头部找到的都是到 已经"建好树"的最短距离以及该节点编号, 并由该节点去更新 树根 到其 ...

  10. L2 Population 原理 - 每天5分钟玩转 OpenStack(113)

    前面我们学习了 VXLAN,今天讨论跟 VXLAN 紧密相关的 L2 Population. L2 Population 是用来提高 VXLAN 网络 Scalability 的. 通常我们说某个系统 ...