代码:

    /// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DrawPanel chart_ = new DrawPanel();
LineCanvas _mask = new LineCanvas();
grid1.Children.Add(chart_);
grid1.Children.Add(_mask);
chart_.plot();
}
}
public class LineCanvas : Canvas
{
public LineCanvas()
{
Background = Brushes.Transparent;
var line = new Line()
{
StrokeThickness = 2,
Stroke = System.Windows.Media.Brushes.Black,
}; this.Children.Add(line);
MouseMove += (send, e) =>
{
Point point = e.GetPosition(this);
line.X1 = point.X;
line.Y1 = 0;
line.X2 = point.X;
line.Y2 = ActualHeight;
};
}
} public class DrawPanel : Panel
{
private DrawingVisual _drawingVisual = new DrawingVisual();
public DrawPanel()
{
this.AddVisualChild(_drawingVisual);
IsHitTestVisible = false;
}
public Pen p = new Pen(Brushes.Gainsboro, 1.0);
public void plot()
{
p.Freeze();
var dc = _drawingVisual.RenderOpen();
_drawingVisual.CacheMode = new BitmapCache();//这句话是关键,加了性能直接提升
for (int x = 0; x < 10000; x++)
{
double xx = 700.0 / 2 + ((x / 10000.0) * (700.0 / 2.0));
Point p1 = new Point(xx, 0);
Point p2 = new Point(xx, 353);
dc.DrawLine(p, p1, p2);
}
dc.Close();
}
protected override int VisualChildrenCount
{
get { return 1; }
}
protected override Visual GetVisualChild(int index)
{
if (index == 0)
return _drawingVisual;
throw new IndexOutOfRangeException();
}
}

WPF绘图性能问题的更多相关文章

  1. 利用WPF绘图

    C#入门经典 25章的一个例子,利用WPF绘图. XAML: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/p ...

  2. Unity 绘图性能优化 - Draw Call Batching

    Unity 绘图性能优化 - Draw Call Batching Unity官方链接:http://docs.unity3d.com/Manual/DrawCallBatching.html 转载请 ...

  3. 最优化WPF 3D性能(基于“Tier-2”硬件)

    原文:最优化WPF 3D性能(基于"Tier-2"硬件) 原文地址:Maximizing WPF 3D Performance on Tier-2 Hardware 开发人员在应用 ...

  4. WPF DataGrid 性能加载大数据

    WPF(Windows Presentation Foundation)应用程序在没有图形加速设备的机器上运行速度很慢是个公开的秘密,给用户的感觉是它太吃资源了,WPF程序的性能和硬件确实有很大的关系 ...

  5. 提高WPF程序性能的几条建议

    这篇博客将介绍一些提高WPF程序的建议(水平有限,如果建议有误,请指正.) 1. 加快WPF程序的启动速度: (1).减少需要显示的元素数量,去除不需要或者冗余的XAML元素代码. (2).使用UI虚 ...

  6. c#+wpf项目性能优化之OutOfMemoryException解密

    近期,使用c#+wpf开发的软件准备正式投入使用了,使用前进行了大量的测试,测试后发现了一些问题,其中最让人头疼的就是软件的性能问题(稳定性). 这里的稳定性具体表现在机器的cpu占有率和内存使用情况 ...

  7. 【转载】WPF DataGrid 性能加载大数据

    作者:过客非归 来源:CSDN 原文:https://blog.csdn.net/u010265681/article/details/76651725 WPF(Windows Presentatio ...

  8. 优化WPF 3D性能

    Maximize WPF 3D Performance .NET Framework 4.5   As you use the Windows Presentation Foundation (WPF ...

  9. WPF 一个性能比较好的 gif 解析库

    本文介绍 Magick.NET ,这是 ImageMagick 的 .Net 封装,他支持 100 多种格式的图片,而 gif 也是他支持的.本文告诉大家如何使用这个库播放 gif 图 先给大家看一下 ...

随机推荐

  1. (转载)——Centos下安装Redis(原文地址:http://www.nnzhp.cn/archives/169)

    原文地址:http://www.nnzhp.cn/archives/169 今天介绍一下redis,重点介绍一下redis的安装. Redis 是一个基于内存的高性能key-value数据库,数据都保 ...

  2. 非旋Treap及其可持久化

    平衡树这种东西,我只会splay.splay比较好理解,并且好打,操作方便. 我以前学过SBT,但并不是很理解,所以就忘了怎么打了. 许多用平衡树的问题其实可以用线段树来解决,我们真正打平衡树的时候一 ...

  3. HTML和css简单日常总结

    今天主要学习了两个部分:第一部分html:在w3school学习了一些标签的使用和一些属性和方法,例如一些标签<a>,<h1><h6><from>< ...

  4. LUOGU P2344 奶牛抗议 (树状数组优化dp)

    传送门 解题思路 树状数组优化dp,f[i]表示前i个奶牛的分组的个数,那么很容易得出$f[i]=\sum\limits_{1\leq j\leq i}f[j-1]*(sum[i]\ge sum[j- ...

  5. 莫烦PyTorch学习笔记(四)——回归

    下面的代码说明个整个神经网络模拟回归的过程,代码含有详细注释,直接贴下来了 import torch from torch.autograd import Variable import torch. ...

  6. vue之vant组件下拉加载更多

    vant地址:https://youzan.github.io/vant/#/zh-CN/intro 基础用法 List 组件通过loading和finished两个变量控制加载状态,当组件滚动到底部 ...

  7. DataGridView绑定DataTable的正确姿势

    1. 将DataTable 绑定到BindingSource 2. 将BindingSource绑定到DataGridView 3. DataGridView修改完要从Datatable取值时,同步过 ...

  8. vue-cli 目录结构详细讲解

    https://juejin.im/post/5c3599386fb9a049db7351a8 vue-cli 目录结构详细讲解 目录 结构预览 ├─build // 保存一些webpack的初始化配 ...

  9. String类的trim() 方法

    用于删除字符串的头尾空白符. 语法:public String trim() 返回值:删除头尾空白符的字符串. public class Test {    public static void ma ...

  10. JVM基础总结