代码:

    /// <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. 2-sat——hdu3062

    对于怎么建边还是不太清楚 选了a,那么b c不选,所以连边 选了b或c,那么a必定不选 /* 每个点拆成i*2,i*2+1 队长选,那么队友不选 队长不选,那么队友必定要选 */ #include&l ...

  2. css - 常见知识点

    1. 盒模型 页面渲染时,dom 元素所采用的 布局模型.可通过box-sizing进行设置.根据计算宽高的区域可分为: content-box (W3C 标准盒模型) border-box (IE ...

  3. vue的无缝滚动插件vue-seamless-scroll的使用

    https://chenxuan0000.github.io/component-document/index_prod.html#/component/seamless-others 在vue环境下 ...

  4. iOS之CALayer属性简介

    /* CoreAnimation - CALayer.h Copyright (c) 2006-2017, Apple Inc. All rights reserved. */ #import < ...

  5. iPhoneX适配随笔

    1.安全区域 2.NavigationBar 和 TabBar的xib示意图 两个View要相同的效果,坐标不同 UIButton *btn = [UIButton buttonWithType:UI ...

  6. tcp为什么要三次握手,四次挥手

    tcp为什么要三次握手,tcp为什么可靠. 为什么不能两次握手:(防止已失效的连接请求又传送到服务器端,因而产生错误) 假设改为两次握手,client端发送的一个连接请求在服务器滞留了,这个连接请求是 ...

  7. jdk工具(转)

    在JDK的bin目录下有很多命令行工具: 我们可以看到各个工具的体积基本上都稳定在27kb左右,这个不是JDK开发团队刻意为之的,而是因为这些工具大多数是jdk\lib\tools.jar类库的一层薄 ...

  8. My solutions to the exercises in "The Boost C++ Libraries"

    I like books with excercises, but I also want solutions to see if I got it right. When working throu ...

  9. <每日一题>题目16:简单的python练习题(1-10)

    #1.python程序中__name__的作用是什么? __name__这个系统变量用来表示程序的运行方式. 如果程序在当前膜快运行,__name__的名称就是__main__, 如果不在(被调用), ...

  10. 【牛客挑战赛31D】 雷的打字机

    题目 首先看到这个出现长度至少为\(2\)的回文子串 这就等价于不能出现两个连续且相同的字符 于是我们用概率生成函数来搞 设\(g_i\)表示\(i\)次操作后游戏没有结束的概率,\(f_{i,j}\ ...