WPF绘图性能问题
代码:
/// <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绘图性能问题的更多相关文章
- 利用WPF绘图
C#入门经典 25章的一个例子,利用WPF绘图. XAML: <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/p ...
- Unity 绘图性能优化 - Draw Call Batching
Unity 绘图性能优化 - Draw Call Batching Unity官方链接:http://docs.unity3d.com/Manual/DrawCallBatching.html 转载请 ...
- 最优化WPF 3D性能(基于“Tier-2”硬件)
原文:最优化WPF 3D性能(基于"Tier-2"硬件) 原文地址:Maximizing WPF 3D Performance on Tier-2 Hardware 开发人员在应用 ...
- WPF DataGrid 性能加载大数据
WPF(Windows Presentation Foundation)应用程序在没有图形加速设备的机器上运行速度很慢是个公开的秘密,给用户的感觉是它太吃资源了,WPF程序的性能和硬件确实有很大的关系 ...
- 提高WPF程序性能的几条建议
这篇博客将介绍一些提高WPF程序的建议(水平有限,如果建议有误,请指正.) 1. 加快WPF程序的启动速度: (1).减少需要显示的元素数量,去除不需要或者冗余的XAML元素代码. (2).使用UI虚 ...
- c#+wpf项目性能优化之OutOfMemoryException解密
近期,使用c#+wpf开发的软件准备正式投入使用了,使用前进行了大量的测试,测试后发现了一些问题,其中最让人头疼的就是软件的性能问题(稳定性). 这里的稳定性具体表现在机器的cpu占有率和内存使用情况 ...
- 【转载】WPF DataGrid 性能加载大数据
作者:过客非归 来源:CSDN 原文:https://blog.csdn.net/u010265681/article/details/76651725 WPF(Windows Presentatio ...
- 优化WPF 3D性能
Maximize WPF 3D Performance .NET Framework 4.5 As you use the Windows Presentation Foundation (WPF ...
- WPF 一个性能比较好的 gif 解析库
本文介绍 Magick.NET ,这是 ImageMagick 的 .Net 封装,他支持 100 多种格式的图片,而 gif 也是他支持的.本文告诉大家如何使用这个库播放 gif 图 先给大家看一下 ...
随机推荐
- thinkphp 命名范围
在应用开发过程中,使用最多的操作还是数据查询操作,凭借ThinkPHP的连贯操作的特性,可以使得查询操作变得更优雅和清晰,命名范围功能则是给模型操作定义了一系列的封装,让你更方便的操作数据. 命名范围 ...
- LUOGU P2764 最小路径覆盖问题 (最小路径点覆盖)
解题思路 有向图最小路径点覆盖问题,有这样的结论就是有向图最小路径点覆盖等于n-拆点二分图中最大匹配.具体怎么证明不太知道..输出方案时找到所有左部未匹配的点一直走$match$就行了. #incl ...
- light oj 1098 数学规律
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> ...
- vue-cli的使用指南
vue-cli 2.0 安装vue-cli npm install -g vue-cli 创建一个项目模板 vue init <template-name> <project-nam ...
- <每日一题>题目8:文件备份V1.0
import os #备份文件的路径 file_address = input("输入需要备份文件所在的路径:") os.chdir(file_address) #备份文件命名 f ...
- SW数据库结构列表
数据表列表 PE_Admin:管理员信息表 PE_Advertisement:广告信息表 PE_AdZone:版位信息表 PE_Announce:公告信息表 PE_AreaCollection:采集信 ...
- Apache 禁用IP 访问 和 HTTP 跳转 HTTPS
如果需要 禁用IP 访问并且 需要 HTTP 跳转到 HTTPS <VirtualHost *:80> ServerName xxx.xxx.com RewriteEngine On Re ...
- 使用 top instance 命令查看运行中 MaxCompute 作业
我们都知道,在 MaxCompute Console 里,可以使用下面的命令来列出运行完成的 instance 列表. show p|proc|processlist [from <yyyy-M ...
- js中call、apply、bind的区别和应用
一.总体概述 这三个方法都是改变函数本身的this指向的,但是略有不同 1.call 使用方法:函数名.call(this指向,展开的参数列表); 如果传入的this指向是null或者是undifin ...
- Yaf--个人封装yaf的框架+swoole+elasticsearch(Window+linux版)
这是基于c写底层的yaf框架集成PDO+predis+读写分离+composer+全局异常处理+多模块开发+Log日志记录简单容易上手的框架 注意:window版没有swoole和Smarty主要用作 ...