背水一战 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的更多相关文章
- 背水一战 Windows 10 (13) - 绘图: Stroke, Brush
[源码下载] 背水一战 Windows 10 (13) - 绘图: Stroke, Brush 作者:webabcd 介绍背水一战 Windows 10 之 绘图 Stroke - 笔划 Brush ...
- 重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush
原文:重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush [源码下载] 重新想象 Windows 8 Store Apps ...
- 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧
[源码下载] 背水一战 Windows 10 (21) - 绑定: x:Bind 绑定, x:Bind 绑定之 x:Phase, 使用绑定过程中的一些技巧 作者:webabcd 介绍背水一战 Wind ...
- 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox
[源码下载] 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox 作者:webabcd ...
- 背水一战 Windows 10 (26) - XAML: x:DeferLoadStrategy, x:Null
[源码下载] 背水一战 Windows 10 (26) - XAML: x:DeferLoadStrategy, x:Null 作者:webabcd 介绍背水一战 Windows 10 之 XAML ...
- 背水一战 Windows 10 (20) - 绑定: DataContextChanged, UpdateSourceTrigger, 对绑定的数据做自定义转换
[源码下载] 背水一战 Windows 10 (20) - 绑定: DataContextChanged, UpdateSourceTrigger, 对绑定的数据做自定义转换 作者:webabcd 介 ...
- 背水一战 Windows 10 (19) - 绑定: TemplateBinding 绑定, 与 RelativeSource 绑定, 与 StaticResource 绑定
[源码下载] 背水一战 Windows 10 (19) - 绑定: TemplateBinding 绑定, 与 RelativeSource 绑定, 与 StaticResource 绑定 作者:we ...
- 背水一战 Windows 10 (18) - 绑定: 与 Element 绑定, 与 Indexer 绑定, TargetNullValue, FallbackValue
[源码下载] 背水一战 Windows 10 (18) - 绑定: 与 Element 绑定, 与 Indexer 绑定, TargetNullValue, FallbackValue 作者:weba ...
- 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果)
[源码下载] 背水一战 Windows 10 (17) - 动画: ThemeTransition(过渡效果) 作者:webabcd 介绍背水一战 Windows 10 之 动画 ThemeTrans ...
随机推荐
- 比官方教程代码更简短的SignalR Server Broadcast示例
SignalR是微软ASP.NET技术体系中的新成员. 在www.asp.net网站上的SignalR专区有一篇SignalR的入门级教程<Tutorial: Server Broadcast ...
- 喜大普奔,微软Microsoft JDBC Driver For SQL Server已发布到maven中央仓库
相信通过java和SQLServer开发应用的同学们都经历过如下类似的问题. 微软提供的JDBC官方驱动没有放置在Maven仓库中,这样如果你的Java应用需要访问SQL Server,你不得不下载s ...
- xamarin UWP证书问题汇总
打算开发一个软件使用rsa加密的东西,所以有用到数字证书这块,最近遇到些问题, 问题一:使用如下代码添加数字证书后,在证书管理器的当前用户和本地计算机下都找不到这张证书. using (X509Sto ...
- iOS-几大框架的介绍
1.Objective-C之Foundation框架 概述 我们前面的章节中就一直新建Cocoa Class,那么Cocoa到底是什么,它和我们前面以及后面要讲的内容到底有什么关系呢?Objectiv ...
- iOS----集成ijkplayer视频直播
ijkplayer 是一款做视频直播的框架, 基于ffmpeg, 支持 Android 和 iOS, 网上也有很多集成说明, 但是个人觉得还是不够详细, 在这里详细的讲一下在 iOS 中如何集成ijk ...
- Entity Framework Core 1.1 Preview 1 简介
实体框架核心(EF Core)是Entity Framework的一个轻量级,可扩展和跨平台版本. 10月25日,Entity Framework Core 1.1 Preview 1发布了. 升级到 ...
- iOS中怎么存储照片到自定义相册
在市场上主流App中,大多数App都具有存储图片到自己App的相册中.苹果提供的方法只能存储图片到系统相册,下面讲一下怎么实现: 实现思路: 1.对系统相册进行操作的前提必须导入#import &l ...
- .NET平台开源项目速览(6)FluentValidation验证组件介绍与入门(一)
在文章:这些.NET开源项目你知道吗?让.NET开源来得更加猛烈些吧!(第二辑)中,给大家初步介绍了一下FluentValidation验证组件.那里只是概述了一下,并没有对其使用和强大功能做深入研究 ...
- 浅谈web语义化
在前端的编程道路上,是否听过html的结构语义化? 是否觉得自己前端嘛,只要做出炫酷的效果,编写出牛逼的JavaScript代码就ok啦.div+css所向无敌,干嘛要用其他标签呢. 是啊,正如上面所 ...
- Objective-C中的老板是这样发通知的(Notification)
通知(Notification)简单的类比一下,公司的老总给下面的员工发通知啦,说明天公司要上市,各部门做一下准备工作.等通知发完,各部门收到后各司其职,做着自己该做的东西.假如Boss是 ...