WPF中绘图
来源:互联网 发布:全自动猫厕所 知乎 编辑:程序博客网 时间:2024/06/05 19:20
WPF中绘图
XAML可以绘制矢量图
基本图形,派生自Shape类
Line—直线段,可以设置笔触(Stroke)
Rectangle—矩形,(Stroke,Fill)
Ellipse—椭圆,(Stroke,Fill)
Polygon—多边形,(Stroke,Fill)
Polyline—折线
Path—路径,各种线组成
直线
<Line X1="10" Y1="20" X2="260" Y2="20" Stroke="Red" StrokeThickness="10"/>
…
使用Path剪裁界面元素
UIElement的Clip属性
Clip属性的类型是Geometry 与 Path的Data属性一致。
如果窗体能被剪切,AllowsTransparency必须设置为True。WindowStyle属性必须为None。
UIElement 中有BitmapEffect(用CPU资源)和Effect(用GPU资源)两个属性为UI元素添加效果。
BitmapEffect:
BevelBitmapEffect—斜角效果
BitmapEffectGroup—复合效果
BlurBitmapEffect—模糊效果
DropShadowBitmapEffect—投影效果
EmbossBitmapEffect—浮雕效果
OuterGlowBitmapEffect—外发光效果
例:
<Button.BitmapEffect> <DropShadowBitmapEffect Direction="-45" Opacity="0.75" ShadowDepth="7"/></Button.BitmapEffect>
Effect
UIElement 类有 Effect属性,它是Effect类型,Effect是抽象类
BlurEffect—模糊效果
DropShadowEffect—投影效果
ShaderEffect—着色器效果
官方滤镜包
wpffx.codeplex.com
变形
RenderTransform:呈现变形 UIElement
只是显示变形,其余的都不变
LayoutTransform:布局变形 FrameworkElement
显示和内容都变
这两个属性都是依赖属性类型时Transform
MatrixTransform 矩阵变形
RotateTransform 旋转变形
ScaleTransform坐标系变形
SkewTransform拉伸变形
TranslateTransform偏移变形
TransformGroup变形组
动画
例:
DoubleAnimationBase:
DoubleAnimation,
DoubleAnimationUsingKeyFrames,
DoubleAnimationUsingPath。
1.简单线性动画
变化时间 Duration
变化终点To
变化幅度By
变化起点From
例:
<Button.RenderTransform> <Translate Transform x:Name="tt" X="0" Y="0"/></Button.RenderTransform>...CLick(... sender,... e){ DoubleAnimation daX = new DoubleAnimation(); DoubleAnimation daY = new DoubleAnimation(); Random r = new Random(); daX.From = 0D; daY.From = 0D; daX.To = r.NextDouble()*300; daY.To = r.NextDouble()*300; Duration duration = new Duration(TimeSpan.FromMilliseconds(300)); daX.Duration = duration; daX.Duration = duration;this.tt.BeginAnimation(TranslateTransform.XProperty,daX);this.tt.BeginAnimation(TranslateTransform.XProperty,daX);}
注意:
daX.From = 0D每次都会从初始位置开始
2.高级动画属性
AccelerationRation 加速速率 0~1
DecelerationRation 减速速率 0~1
SpeedRatio 实际播放速度与正常速度之比
AutoReverse 反向播放
RepeatBehavior 重复次数
BeginTime 播放前等待
EasingFunction 缓冲式渐变
3.关键帧动画
DoubleAnimationUsingKeyFrames
<Button.RenderTransform> <Translate Transform x:Name="tt" X="0" Y="0"/></Button.RenderTransform>... DoubleAnimationUsingKeyFrames dakX= new DoubleAnimationUsingKeyFrames(); DoubleAnimationUsingKeyFrames dakY= new DoubleAnimationUsingKeyFrames(); Duration duration = new Duration(TimeSpan.FromMilliseconds(300)); daX.Duration = duration; daX.Duration = duration; ... LinearDoubleKeyFrame x_lf_1 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame x_lf_2 = new LinearDoubleKeyFrame(); LinearDoubleKeyFrame x_lf_3 = new LinearDoubleKeyFrame(); x_lf_1 .KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)); x_lf_1 .Value = 200 x_lf_2 .KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(600)); x_lf_2 .Value = 0 x_lf_3 .KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(900)); x_lf_3 .Value = 200 dakX.Add(x_lf_1 ); dakX.Add(x_lf_2 ); dakX.Add(x_lf_3 ); ...
KeyTime.FromTimeSpan绝对时间
KeyTime.FromPercent相对时间
4.特殊的关键帧
DoubleAnimationUsingKeyFrames 的 KeyFrames属性是DoubleKeyFrameCollection,它可以接收DoubleKeyFrame元素。
DoubleKeyFrame:
LinearDoubleKeyFrame—线性变化关键帧
DiscreteDoubleKeyFrame—不连续变化关键帧
EasingDoubleKeyFrame—缓冲式变化关键帧
SplineDoubleKeyFrame—样条变化式关键帧,贝塞尔曲线
例:
DoubleAnimationUsingKeyFrames dakX= new DoubleAnimationUsingKeyFrames();Duration duration = new Duration(TimeSpan.FromMilliseconds(300)); daX.Duration = duration;SplineDoubleKeyFrame skf = new SplineDoubleKeyFrame();kf.KeyTime = KeyTime.FromPercent(1);kf.Value = 400;KeySpline ks = new KeySpline();ks.ControlPoint1 = new Point(0,1);ks.ControlPoint2 = new Point(1,0);kf.KeySpline = ks;dakX.KeyFrames.Add(kf);
5.路径动画
DoubleAnimationUsingPath
- WPF中绘图
- WPF绘图
- C#的WPF程序中使用XAML绘图示例
- WPF在Canvas中绘图实现折线统计图
- WPF在Canvas中绘图实现折线统计图
- WPF绘图代码
- wpf DrawingContext 绘图方式
- WPF之绘图
- C# WPF Canvas绘图
- WPF绘图控件
- WPF几何绘图之概述
- wpf轻量绘图DrawingVisual
- 以WPF绘图简单的圆形
- 以WPF绘图简单的圆形
- 以WPF绘图简单的圆形
- 以WPF绘图简单的圆形
- 以WPF绘图简单的圆形
- 以WPF绘图简单的圆形
- 二、Matplotlib系列---pyplot的plot( )函数
- JAVA--多线程中notify()造成的死锁原因的研究与使用
- Python学习随笔七:高级特性
- C和C++中struct区别
- vi 切换
- WPF中绘图
- android 媒体框架学习--mediaplayerservice 关系类图
- opencv2.4.9 绘制一维直方图
- IGBT最不为人知的神秘损坏原因!
- 五笔字典编码-------------->_<
- 【Redis手册一】常用命令
- LA -- 3029 City Game 【思维 + dp】
- hdu 6162 Ch’s gift(主席树)
- 安卓ProgressBar水平进度条的颜色设置