相关知识参考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. loadrunner11安装与破解

    最近准备学习LR,借助这个平台,将自己的学习经历记录下来,当然很多都不是原创,都是遇到问题时各种百度,然后梳理下知识是为了避免以后遇到同样的错误时,能回过头来参考参考. 下面的是转载某位大神的博客,尊 ...

  2. 百度地图API 学习网站

    官方示例:http://developer.baidu.com/map/jsdemo.htm#a1_2 (注意:此网页可能由于浏览器问题,源代码编辑器中的代码不能看到.火狐亲测有效) http://d ...

  3. 学习练习 java输入输出流 练习题1

    .编写TextRw.java的Java应用程序,程序完成的功能是:首先向TextRw.txt中写入自己的学号和姓名,读取TextRw.txt中信息并将其显示在屏幕上. package com.hanq ...

  4. 使用ngin的静态文件下载

    1,主配置文件nginx.xml #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error. ...

  5. CLRS:max_heap and min_heap operation (pseudocode)

    //max_heap heap_maximum:return A[1]    O(1); Extract_Heap_maximum:swap(A[1],A[heap.size])    adjust ...

  6. linux 内核(驱动)常用函数

    2.4.1 内存申请和释放 include/linux/kernel.h里声明了kmalloc()和kfree().用于在内核模式下申请和释放内存.    void *kmalloc(unsigned ...

  7. Android IOS WebRTC 音视频开发总结(四六)-- 从另一个角度看国内首届WebRTC大会

    文章主要从开发者角度谈国内首届WebRTC大会,支持原创,文章来自博客园RTC.Blacker,支持原创,转载必须说明出处,更多详见www.rtc.help. -------------------- ...

  8. 【EF学习笔记03】----------使用原生Sql语句

    在EF中使用原生SQL,首先要创建上下文对象 using (var db = new Entities()) { //数据操作 } 新增 string sql = "insert into ...

  9. .NET Framework 中的字符编码

    字符是可用多种不同方式表示的抽象实体. 字符编码是一种为受支持字符集中的每个字符进行配对的系统,配对时使用的是表示该字符的某些值. 例如,摩尔斯电码是一种为罗马字母表中的每个字符进行配对的字符编码,配 ...

  10. MallBuilder 多用户商城管理系统 v5.8.1.1

    MallBuilder是一款基于PHP+MYSQL的多用户网上商城解决方案.利用MallBuilder可以快速建立一个功能强大的类似京东商城.天猫商城.1号店商城的网上商城,或企业.行业化.本地化和垂 ...