相关知识参考DrawTool画笔之纹理笔  , 图形笔的实现跟纹理笔的实现是一样的,重载Stroke的DrawCore方法,效果图:

------------------------------------------------------------

代码如下:

/// <summary>
/// 图形笔
/// </summary>
public class ImageStroke : Stroke
{
private string imageFile_;
private System.Windows.Media.ImageSource imageSource_;
private Point curPoint;
public ImageStroke(System.Windows.Input.StylusPointCollection points, DrawingAttributes da, string file)
: base(points, da)
{
this.imageFile_ = file;
this.imageSource_ = new System.Windows.Media.Imaging.BitmapImage(new Uri( this.imageFile_));
} protected override void DrawCore(System.Windows.Media.DrawingContext drawingContext, DrawingAttributes drawingAttributes)
{
double num = drawingAttributes.Width + 20.0;
System.Windows.Media.StreamGeometry streamGeometry = new System.Windows.Media.StreamGeometry();
using (System.Windows.Media.StreamGeometryContext streamGeometryContext = streamGeometry.Open())
{
streamGeometryContext.BeginFigure((Point)base.StylusPoints[], false, false);
drawingContext.DrawImage(this.imageSource_, new Rect(((Point)base.StylusPoints[]).X - num / 2.0, ((Point)base.StylusPoints[]).Y - num / 2.0, num, num));
this.curPoint = (Point)base.StylusPoints[];
foreach (System.Windows.Input.StylusPoint current in base.StylusPoints)
{
ImageStroke.DrawImage(ref this.curPoint, (Point)current, num, drawingContext, this.imageSource_);
}
}
} public static double GetDistance(Point a, Point b)
{
return System.Math.Abs(Point.Subtract(a, b).Length);
}
public static Point GetPointBetween(Point a, Point b, double len)
{
Vector vector = Point.Subtract(a, b);
vector.Normalize();
vector = Vector.Multiply(vector, len);
return Point.Subtract(a, vector);
} public static void DrawImage(ref Point a, Point b, double width, System.Windows.Media.DrawingContext drawingContext, System.Windows.Media.ImageSource imageSource)
{
for (double distance = ImageStroke.GetDistance(a, b); distance >= width; distance = ImageStroke.GetDistance(a, b))
{
Point pointBetween = ImageStroke.GetPointBetween(a, b, width);
drawingContext.DrawImage(imageSource, new Rect(pointBetween.X - width / 2.0, pointBetween.Y - width / 2.0, width, width));
a = pointBetween;
}
}
}

实例应用可以参考纹理笔,在生成stroke对象时候使用ImageStroke然后将stroke添加到inkcanvas的strokes集合中

DrawTool画笔之图形笔的更多相关文章

  1. DrawTool画笔之纹理笔

    先上图: 今天我们要实现的是DrawTool画笔集合中的一种纹理笔,很多人可能对纹理笔概念还比较生疏,其实如果你接触过类似一些教育行业交互式白板的话,对纹理笔并不会感到陌生,纹理笔我们可以简单的理解为 ...

  2. 2048游戏_QT实现

    #ifndef GAMEWIDGET_H #define GAMEWIDGET_H #include <QWidget> #include <QMouseEvent> #inc ...

  3. GDI+编程说明及小结

    原文地址:http://blog.csdn.net/byxdaz/article/details/5972759 GDI+(Graphics Device Interface Plus图形设备接口加) ...

  4. GDI编程

    图形设备接口(GDI)是一个可执行程序,它接受Windows应用程序的绘图请求(表现为GDI函数调用),并将它们传给相应的设备驱动程序,完成特定于硬件的输出,象打印机输出和屏幕输出.GDI负责Wind ...

  5. 自定义View类

    一.如何创建自定义的View类 ①.创建一个继承android.view.View类的Java类,并且重写构造方法(至少需要重写一个构造方法) ②.根据需要重写其他方法 ③.在项目的活动中,创建并实例 ...

  6. Note of Python Turtle

    Note of Python Turtle         Turtle 库函数是 Python语言中一个流行的绘图函数库.Turtle 意思是海龟,在Python中显示为一个小箭头,通过它的移动而留 ...

  7. GDI+编程小结

    GDI+(Graphics Device Interface Plus图形设备接口加)是Windows XP和Windows Server 2003操作系统的子系统,也是.NET框架的重要组成部分,负 ...

  8. 从0开始学自定义View -1

    PS:好久没有写博客了,之前的东西有所忘记,百度一下竟然查到了自己的写过的博客,访问量还可以,一开始的写博客的初衷是把自己不会的记录下来,现在没想到也有博友会关注我,这就给了我动力,工作之余把零零碎碎 ...

  9. 导航程序调试1---MFC应用以及数据显示程序

    问题 error C2664: "BuildCommDCBW": 不能将参数 1 从"char *"转换为"LPCWSTR"经常出现这样的错 ...

随机推荐

  1. 使用MonkeyTest对Android客户端进行压力测试 自动化代码

    1.monkey命令简介 Monkey是Android中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序 ...

  2. Yii 中比较常用的rules验证规则记录

    查看代码   打印 01 return array( 02   03     //必须填写 04     array('email, username, password,agree,verifyPa ...

  3. [jPlayer] HTML5 Audio & Video for jQuery

    ---------------------------------------------------------------------------------------------------- ...

  4. CentOS 6.5 Maven 编译 Apache Tez 0.8.3 踩坑/报错解决记录

    最近准备学习使用Tez,因此从官网下载了最新的Tez 0.8.3源码,按照安装教程编译使用.平时使用的集群环境是离线的,本打算这一次也进行离线编译,无奈一编译就开始报缺少jar包的错,即使手动下载ja ...

  5. 【PL/SQL练习】函数

    1.必须返回一个值2.只能在表达式调用 SQL> create or replace function fun1 return number is v_sum_sal emp.sal%type; ...

  6. springMVC导入excel案例poi

    直接上代码: 第一步,controller 引入 private static final String CHECK_FILE = "checkExceFile"; /** * 对 ...

  7. 关键字 this 的作用

    1.关键字 this ①是指当前对象自己 当一个类中要明确指出使用对象自己的变量或函数时,就应该加上this关键字,小栗子a如下: public class A { string Name = &qu ...

  8. 在集群环境中使用 EhCache 缓存系统|RMI 集群模式

    RMI 是 Java 的一种远程方法调用技术,是一种点对点的基于 Java 对象的通讯方式.EhCache 从 1.2 版本开始就支持 RMI 方式的缓存集群.在集群环境中 EhCache 所有缓存对 ...

  9. 使用Servlet处理请求<http://blog.sina.com.cn/s/blog_5d3fb3cc0100ep9q.html>

    一.GET和POST的区别 1.GET提交的是文本内容,规定其数据长度不超过255个字符.在GET方式提交的URL中会显示出提交的查询数据而却提交数据的缓存会在浏览器的URL历史状态中,这样我们往往在 ...

  10. 【Qt】使用QProcess调用其它程序或脚本

    大概试了一下,还是不错的,不过字符编码问题还不太好解决: 代码: #include "mainwindow.h" #include "ui_mainwindow.h&qu ...