【LinearGradientBrush】线性渐变笔刷

摘要:
XAML<GradientStopColor=“Red”偏移=“0.25”/>myLinearGradientBrush.StartPoint=newPoint(0;//使用画笔绘制矩形。对角线填充矩形。填充=myLinearGradientBrush;

本示例演示如何使用 LinearGradientBrush 类来绘制带有线性渐变的区域。在下面的示例中,Rectangle 的Fill 是用从黄色依次过渡到红色、蓝色和浅绿色的对角线性渐变来绘制的。

XAML
<!-- This rectangle is painted with a diagonal linear gradient. --> <Rectangle Width="200" Height="100">   <Rectangle.Fill>     <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">       <GradientStop Color="Yellow" Offset="0.0" />       <GradientStop Color="Red" Offset="0.25" />       <GradientStop Color="Blue" Offset="0.75" />       <GradientStop Color="LimeGreen" Offset="1.0" />     </LinearGradientBrush>   </Rectangle.Fill> </Rectangle> 
C#
Rectangle diagonalFillRectangle = new Rectangle(); diagonalFillRectangle.Width = 200; diagonalFillRectangle.Height = 100;  // Create a diagonal linear gradient with four stops.    LinearGradientBrush myLinearGradientBrush =     new LinearGradientBrush(); myLinearGradientBrush.StartPoint = new Point(0,0); myLinearGradientBrush.EndPoint = new Point(1,1); myLinearGradientBrush.GradientStops.Add(     new GradientStop(Colors.Yellow, 0.0)); myLinearGradientBrush.GradientStops.Add(     new GradientStop(Colors.Red, 0.25));                 myLinearGradientBrush.GradientStops.Add(     new GradientStop(Colors.Blue, 0.75));         myLinearGradientBrush.GradientStops.Add(     new GradientStop(Colors.LimeGreen, 1.0));  // Use the brush to paint the rectangle. diagonalFillRectangle.Fill = myLinearGradientBrush; 

下图显示了上一示例创建的渐变。

对角线方向线性渐变

若要创建水平线性渐变,请将 LinearGradientBrush 的 StartPoint 和 EndPoint 分别改为 (0,0.5) 和 (1,0.5)。在下面的示例中,Rectangle 是用水平线性渐变来绘制的。

XAML
<!-- This rectangle is painted with a horizontal linear gradient. --> <Rectangle Width="200" Height="100">   <Rectangle.Fill>     <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">       <GradientStop Color="Yellow" Offset="0.0" />       <GradientStop Color="Red" Offset="0.25" />       <GradientStop Color="Blue" Offset="0.75" />       <GradientStop Color="LimeGreen" Offset="1.0" />     </LinearGradientBrush>   </Rectangle.Fill> </Rectangle> 
C#
Rectangle horizontalFillRectangle = new Rectangle(); horizontalFillRectangle.Width = 200; horizontalFillRectangle.Height = 100;  // Create a horizontal linear gradient with four stops.    LinearGradientBrush myHorizontalGradient =     new LinearGradientBrush(); myHorizontalGradient.StartPoint = new Point(0,0.5); myHorizontalGradient.EndPoint = new Point(1,0.5); myHorizontalGradient.GradientStops.Add(     new GradientStop(Colors.Yellow, 0.0)); myHorizontalGradient.GradientStops.Add(     new GradientStop(Colors.Red, 0.25));                 myHorizontalGradient.GradientStops.Add(     new GradientStop(Colors.Blue, 0.75));         myHorizontalGradient.GradientStops.Add(     new GradientStop(Colors.LimeGreen, 1.0));  // Use the brush to paint the rectangle. horizontalFillRectangle.Fill = myHorizontalGradient;   

下图显示了上一示例创建的渐变。

水平线性渐变

若要创建垂直线性渐变,请将 LinearGradientBrush 的 StartPoint 和 EndPoint 分别改为 (0.5,0) 和 (0.5,1)。在下面的示例中,Rectangle 是用垂直线性渐变来绘制的。

XAML
<!-- This rectangle is painted with a vertical gradient. --> <Rectangle Width="200" Height="100">   <Rectangle.Fill>     <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">       <GradientStop Color="Yellow" Offset="0.0" />       <GradientStop Color="Red" Offset="0.25" />       <GradientStop Color="Blue" Offset="0.75" />       <GradientStop Color="LimeGreen" Offset="1.0" />     </LinearGradientBrush>   </Rectangle.Fill> </Rectangle> 
C#
Rectangle verticalFillRectangle = new Rectangle(); verticalFillRectangle.Width = 200; verticalFillRectangle.Height = 100;  // Create a vertical linear gradient with four stops.    LinearGradientBrush myVerticalGradient =     new LinearGradientBrush(); myVerticalGradient.StartPoint = new Point(0.5,0); myVerticalGradient.EndPoint = new Point(0.5,1); myVerticalGradient.GradientStops.Add(     new GradientStop(Colors.Yellow, 0.0)); myVerticalGradient.GradientStops.Add(     new GradientStop(Colors.Red, 0.25));                 myVerticalGradient.GradientStops.Add(     new GradientStop(Colors.Blue, 0.75));         myVerticalGradient.GradientStops.Add(     new GradientStop(Colors.LimeGreen, 1.0));  // Use the brush to paint the rectangle. verticalFillRectangle.Fill = myVerticalGradient;   

下图显示了上一示例创建的渐变。

垂直线性渐变
【LinearGradientBrush】线性渐变笔刷第4张说明:

此主题中的示例使用默认坐标系来设置起点和终点。默认坐标系是相对于边界框的:0 表示边界框的 0%,1 表示边界框的 100%。可以通过将 MappingMode 属性设置为值 BrushMappingMode..::.Absolute 来更改此坐标系。绝对坐标系不是相对于边界框的。值直接在本地坐标系中解释。

有关更多示例,请参见 Brush 示例。有关渐变以及其他类型的画笔的更多信息,请参见使用纯色和渐变进行绘制概述

更多代码

如何:使用径向渐变绘制区域本示例演示如何使用 RadialGradientBrush 类来绘制带有径向渐变的区域。

免责声明:文章转载自《【LinearGradientBrush】线性渐变笔刷》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇js正则匹配获取文件名MySQL 5.6表空间传输下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Asp.NET导出Excel文件乱码解决若干方法 (转)

  Asp.NET导出Excel文件乱码解决若干方法 在Asp.NET开发过程中经常会将一些列表项目导出为Excel方便用户查看和保存,但是也经常遇到文件名乱码、文件内容乱码等问题。最近我也接到了这样的Bug,现总结了若干个解决办法,供遇到问题的朋友们参考一下。希望以下的某些方法可以解决您的问题。   程序逻辑及问题  前端点击导出Excel之后,从后台...

Spring RestTemplate简介及使用

Spring RestTemplate介绍 1、springRestTemplate 简介 spring 提供的同步请求Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效率。 是Spring用于同步client端的核心类,简化了与http服务的通信,并满足RestFul原则,程序代码可以给它提...

搜索插件——autocomplete

搜索插件的功能是通过插件的autocomplete()方法与文本框相绑定,当文本框输入字符时,绑定后的插件将返回与字符相近的字符串提示选择,调用格式如下: $(textbox).autocomplete(urlData,[options]); 其中,textbox参数为文本框元素名称,urlData为插件返回的相近字符串数据,可选项参数options为调用...

Android color颜色-色号总结

code时经常会用到颜色,然而对于像我这样的对于颜色不是很敏感的同学来说,就很痛苦了。 我想要某种颜色,但是又说不出来具体是哪种;这边总结了一下color种类以及色号。 <?xml version="1.0" encoding="utf-8"?> <resources> <color name="white"...

注解-组件注册02-@ComponentScan

  当需要扫描一个包下的所有注解时,可以在XML文件中进行配置: <!--包扫描,只要标注了@Controller、@Service、@Reposotory、@Component就可以被加载到spring bean容器--> <context:component-scan base-package="spring_annotation....

流量取证-流量中提取文件

以前整理的一些东西,拿出来做备忘 PCAP 报文就是抓取实际在网络中传输的图片,视频等数据,然后以PCAP 格式存储形成的文件。工作中对离线的数据包进行回溯分析,有时会遇到将 PCAP 中的码流还原成相应的图片、视频、邮件等原有格式的需求。 从流量中取证文件大部分情况下是为了提取流量中的可执行程序。 1、 tcpxtract 安装: apt-get ins...