当图片转svg,svg转Xaml后,根据数据加载显示图片

DrawingImage:

     <DrawingImage x:Key="Image.Search">
<DrawingImage.Drawing>
<GeometryDrawing>
<GeometryDrawing.Brush>
<SolidColorBrush Color="#FF666666" Opacity="0.5" />
</GeometryDrawing.Brush>
<GeometryDrawing.Geometry>
<PathGeometry FillRule="Nonzero"
Figures="M6.5,2C4.01471853256226,2 2,4.01471853256226 1.99999988079071,6.5 2,8.98528099060059 4.01471853256226,11 6.5,11 8.98528099060059,11 11,8.98528099060059 11,6.5 11,4.01471853256226 8.98528099060059,2 6.5,2z M6.5,1.00000011920929C9.53756618499756,1 12,3.46243381500244 12,6.5 12,7.65749835968018 11.6424360275269,8.73148345947266 11.03173828125,9.61752414703369L13.9562683105469,12.5420551300049C14.3431911468506,12.9289779663086 14.3429946899414,13.5565004348755 13.9497470855713,13.9497470855713 13.5592231750488,14.3402719497681 12.923752784729,14.3379669189453 12.5420551300049,13.9562683105469L9.61752414703369,11.03173828125C8.73148345947266,11.6424360275269 7.65749835968018,12 6.5,12 3.46243381500244,12 1,9.53756618499756 0.999999940395355,6.5 1,3.46243381500244 3.46243381500244,1 6.5,1.00000011920929z" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>

也有可能,同时也需要Geometry:

     <StreamGeometry x:Key="Path.Stream.Search">
M6.5,2C4.01471853256226,2 2,4.01471853256226 1.99999988079071,6.5 2,8.98528099060059 4.01471853256226,11 6.5,11 8.98528099060059,11 11,8.98528099060059 11,6.5 11,4.01471853256226 8.98528099060059,2 6.5,2z M6.5,1.00000011920929C9.53756618499756,1 12,3.46243381500244 12,6.5 12,7.65749835968018 11.6424360275269,8.73148345947266 11.03173828125,9.61752414703369L13.9562683105469,12.5420551300049C14.3431911468506,12.9289779663086 14.3429946899414,13.5565004348755 13.9497470855713,13.9497470855713 13.5592231750488,14.3402719497681 12.923752784729,14.3379669189453 12.5420551300049,13.9562683105469L9.61752414703369,11.03173828125C8.73148345947266,11.6424360275269 7.65749835968018,12 6.5,12 3.46243381500244,12 1,9.53756618499756 0.999999940395355,6.5 1,3.46243381500244 3.46243381500244,1 6.5,1.00000011920929z
</StreamGeometry>

如何将俩种引用方式,提取Path数据重用?

StreamGeometry不行, 没有相应的属性可以支持。。。。

所以我们换个Geomery,虽然没有StreamGeometry性能好。。。

同时,使用PathFigureCollection装载Path数据,然后PathGeometry、DrawingImage 引用资源。

     <PathFigureCollection x:Key="PathData">M6.5,2C4.01471853256226,2 2,4.01471853256226 1.99999988079071,6.5 2,8.98528099060059 4.01471853256226,11 6.5,11 8.98528099060059,11 11,8.98528099060059 11,6.5 11,4.01471853256226 8.98528099060059,2 6.5,2z M6.5,1.00000011920929C9.53756618499756,1 12,3.46243381500244 12,6.5 12,7.65749835968018 11.6424360275269,8.73148345947266 11.03173828125,9.61752414703369L13.9562683105469,12.5420551300049C14.3431911468506,12.9289779663086 14.3429946899414,13.5565004348755 13.9497470855713,13.9497470855713 13.5592231750488,14.3402719497681 12.923752784729,14.3379669189453 12.5420551300049,13.9562683105469L9.61752414703369,11.03173828125C8.73148345947266,11.6424360275269 7.65749835968018,12 6.5,12 3.46243381500244,12 1,9.53756618499756 0.999999940395355,6.5 1,3.46243381500244 3.46243381500244,1 6.5,1.00000011920929z</PathFigureCollection>
<PathGeometry x:Key="Path.Search" Figures="{StaticResource PathData}"/>
<DrawingImage x:Key="Image.Search">
<DrawingImage.Drawing>
<GeometryDrawing>
<GeometryDrawing.Brush>
<SolidColorBrush Color="#FF666666" Opacity="0.5" />
</GeometryDrawing.Brush>
<GeometryDrawing.Geometry>
<PathGeometry FillRule="Nonzero"
Figures="{StaticResource PathData}" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>

显示效果:

 <Window x:Class="WpfApp8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp8"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Window.Resources>
<StreamGeometry x:Key="Path.Stream.Search">
M6.5,2C4.01471853256226,2 2,4.01471853256226 1.99999988079071,6.5 2,8.98528099060059 4.01471853256226,11 6.5,11 8.98528099060059,11 11,8.98528099060059 11,6.5 11,4.01471853256226 8.98528099060059,2 6.5,2z M6.5,1.00000011920929C9.53756618499756,1 12,3.46243381500244 12,6.5 12,7.65749835968018 11.6424360275269,8.73148345947266 11.03173828125,9.61752414703369L13.9562683105469,12.5420551300049C14.3431911468506,12.9289779663086 14.3429946899414,13.5565004348755 13.9497470855713,13.9497470855713 13.5592231750488,14.3402719497681 12.923752784729,14.3379669189453 12.5420551300049,13.9562683105469L9.61752414703369,11.03173828125C8.73148345947266,11.6424360275269 7.65749835968018,12 6.5,12 3.46243381500244,12 1,9.53756618499756 0.999999940395355,6.5 1,3.46243381500244 3.46243381500244,1 6.5,1.00000011920929z
</StreamGeometry> <PathFigureCollection x:Key="PathData">M6.5,2C4.01471853256226,2 2,4.01471853256226 1.99999988079071,6.5 2,8.98528099060059 4.01471853256226,11 6.5,11 8.98528099060059,11 11,8.98528099060059 11,6.5 11,4.01471853256226 8.98528099060059,2 6.5,2z M6.5,1.00000011920929C9.53756618499756,1 12,3.46243381500244 12,6.5 12,7.65749835968018 11.6424360275269,8.73148345947266 11.03173828125,9.61752414703369L13.9562683105469,12.5420551300049C14.3431911468506,12.9289779663086 14.3429946899414,13.5565004348755 13.9497470855713,13.9497470855713 13.5592231750488,14.3402719497681 12.923752784729,14.3379669189453 12.5420551300049,13.9562683105469L9.61752414703369,11.03173828125C8.73148345947266,11.6424360275269 7.65749835968018,12 6.5,12 3.46243381500244,12 1,9.53756618499756 0.999999940395355,6.5 1,3.46243381500244 3.46243381500244,1 6.5,1.00000011920929z</PathFigureCollection>
<PathGeometry x:Key="Path.Search" Figures="{StaticResource PathData}"/>
<DrawingImage x:Key="Image.Search">
<DrawingImage.Drawing>
<GeometryDrawing>
<GeometryDrawing.Brush>
<SolidColorBrush Color="#FF666666" Opacity="0.5" />
</GeometryDrawing.Brush>
<GeometryDrawing.Geometry>
<PathGeometry FillRule="Nonzero"
Figures="{StaticResource PathData}" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Window.Resources>
<Grid>
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<Path Fill="Red" Data="{StaticResource Path.Stream.Search}"/>
<Path Fill="Red" Data="{StaticResource Path.Search}"/>
<Image Source="{StaticResource Image.Search}" Margin="0 10 0 0" Stretch="None"></Image>
</StackPanel>
</Grid>
</Window>

WPF Geometry 添加Path数据的更多相关文章

  1. WPF获得PNG图片外观Path数据

    原文:WPF获得PNG图片外观Path数据        WPF开发界面的时候,用的最多的就是自定义控件模板,开发人员需要根据UI的设计,做出符合要求的自定义控件.但是在一些特殊情况下,UI的设计可能 ...

  2. 在WPF中添加3D特性

    原文:在WPF中添加3D特性 35.4  在WPF中添加3D特性 本节介绍WPF中的3D特性,其中包含了开始使用该特性的信息. 提示: WPF中的3D特性在System.Windows.Media.M ...

  3. Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据

    背景 Python中,想要打开已经存在的excel的xls文件,然后在最后新的一行的数据. 折腾过程 1.找到了参考资料: writing to existing workbook using xlw ...

  4. WPF DataGrid添加编号列

    WPF DataGrid添加编号列? 第一步:<DataGridTemplateColumn Header="编号" Width="50" MinWidt ...

  5. caffe添加python数据层

    caffe添加python数据层(ImageData) 在caffe中添加自定义层时,必须要实现这四个函数,在C++中是(LayerSetUp,Reshape,Forward_cpu,Backward ...

  6. linux下查看和添加PATH环境变量

    linux下查看和添加PATH环境变量 $PATH:决定了shell将到哪些目录中寻找命令或程序,PATH的值是一系列目录,当您运行一个程序时,Linux在这些目录下进行搜寻编译链接. 编辑你的 PA ...

  7. Mac 可设置环境变量的位置、查看和添加PATH环境变量

    Mac 启动加载文件位置(可设置环境变量) ------------------------------------------------------- (1)首先要知道你使用的Mac OS X是什 ...

  8. ArcEngine批量添加XY数据

    使用ArcGIS Desktop “添加XY数据”或者“创建XY事件图层”工具 可以导入Excel坐标数据,生成临时图层并添加至ArcMap.ArcGlobe或者ArcScene中.在ArcEngin ...

  9. thinkphp添加空数据的解决办法

    thinkphp真是个麻烦的东西,各种小问题,其中字段映射的表单名不能与数据库的字段名称相同,否则会添加空数据! 还有自动完成的名称要与字段映射后的名称相同,否则自动完成不会起作用! 还有自动验证的字 ...

随机推荐

  1. hystrix基本介绍和使用(1)

    一.hystrix基本介绍 Hystrix(https://github.com/Netflix/Hystrix)是Netflix(https://www.netflix.com/global)的一个 ...

  2. Eclipse 出现项目没有错但是项目名称却有红色感叹号或者红叉的解决办法

    错误的起因是本人因为一不小心点了下面圈出来的某一个按钮,具体记不清楚了(好像是"remove from build path"),然后整个项目变得很奇怪了,所有的包都变成了一个普通 ...

  3. 机器学习周志华 pdf统计学习人工智能资料下载

    周志华-机器学习 pdf,下载地址: https://u12230716.pipipan.com/fs/12230716-239561959 统计学习方法-李航,  下载地址: https://u12 ...

  4. Ubuntu命令用法详解——curl命令

    简介: cURL(CommandLine Uniform Resource Locator)是一个利用URL语法在命令行下工作的文件传输工具,1997年首次发行.它支持文件上传和下载,所以是综合传输工 ...

  5. 介绍几款 Python 类型检查工具

    近日,微软在 Github 上开源了一个 Python 静态类型检查工具:pyright ,引起了社区内的多方关注. 微软在开源项目上的参与力度是越来越大了,不说收购 Github 这种大的战略野心, ...

  6. Unity C#笔记 委托&事件

    C#的委托与事件搭配,即是观察者模式的一种实现. 因为观察者模式的原理很易懂,不作多讲,本文纯粹用于记录语法. delegate(委托) //声明没有参数,没有返回值的委托类型XXXX public ...

  7. 带你搭一个SpringBoot+SpringData JPA的环境

    前言 只有光头才能变强. 文本已收录至我的GitHub仓库,欢迎Star:https://github.com/ZhongFuCheng3y/3y 不知道大家对SpringBoot和Spring Da ...

  8. WebApi用户登录验证及服务器端用户状态存取

    最近项目需要给手机端提供数据,采用WebApi的方式,之前的权限验证设计不是很好,这次采用的是Basic基础认证. 1.常见的认证方式 我们知道,asp.net的认证机制有很多种.对于WebApi也不 ...

  9. UiPath如何实现暂停功能?

    照理说一个无人值守的机器人原本是不应该有人工操作介入的,也就不会提供暂停功能.但客户可能出于业务需要,或者风险管控的考虑,会需要机器人具备暂停功能.通常,会希望在机器人运行时,用户摁下快捷键,机器人就 ...

  10. 全球第一免费开源ERP Odoo仓存功能模块深度应用(一)

    基本功能 库位 库位是一个逻辑存货区,可以是一个物理库区,可以是一个货架.货架上的一个货位.库位可以有子库位 库位有虚拟库位和实际库位,实际库位是实际存放货物的库位,虚拟库位是因复式库存记账而虚构的库 ...