为了提高GDI+绘图的性能,我用了双缓冲,但是看很多帖子可以利用CachedBitmap、BitBlt和DirectX来达到更好的效果,但是例子都是VB或者其他的,所以请大家帮忙提供一下关于上面说的三种的C#的例子。(最好能和我给出的代码结合,超级感谢)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;namespace simplebitmap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//画图操作
public void DrawLines(Graphics g)
{
float width = ClientRectangle.Width;
float height = ClientRectangle.Height;
float partX = width / 1000;
float partY = height / 1000;
for (int i = 0; i < 1000; i++)
{
g.DrawLine(Pens.Red, 0, height - (partY * i), partX * i, 0);
g.DrawLine(Pens.Yellow, 0, height - (partY * i), (width) - partX * i, 0);
g.DrawLine(Pens.Blue, 0, partY * i, (width) - partX * i, 0);
}
}
//普通的绘制
private void Simple_Click(object sender, EventArgs e)
{
// 通过‘this’创建Graphics对象
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
// 画线
DrawLines(g);
// 释放创建的对象
g.Dispose(); } //利用双缓冲
private void Bitmap_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
// 创建一个 Bitmap 对象 ,大小为窗体大小
Bitmap curBitmap = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
// 创建一个临时 Graphics 对象
Graphics g1 = Graphics.FromImage(curBitmap);
// 通过临时Graphics 对象绘制线条
DrawLines(g1);
// 调用Graphics 对象的DrawImage方法,并画位图
g.DrawImage(curBitmap, 0, 0);
// 释放创建的对象
g1.Dispose();
curBitmap.Dispose();
g.Dispose();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;namespace simplebitmap
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//画图操作
public void DrawLines(Graphics g)
{
float width = ClientRectangle.Width;
float height = ClientRectangle.Height;
float partX = width / 1000;
float partY = height / 1000;
for (int i = 0; i < 1000; i++)
{
g.DrawLine(Pens.Red, 0, height - (partY * i), partX * i, 0);
g.DrawLine(Pens.Yellow, 0, height - (partY * i), (width) - partX * i, 0);
g.DrawLine(Pens.Blue, 0, partY * i, (width) - partX * i, 0);
}
}
//普通的绘制
private void Simple_Click(object sender, EventArgs e)
{
// 通过‘this’创建Graphics对象
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
// 画线
DrawLines(g);
// 释放创建的对象
g.Dispose(); } //利用双缓冲
private void Bitmap_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
g.Clear(this.BackColor);
// 创建一个 Bitmap 对象 ,大小为窗体大小
Bitmap curBitmap = new Bitmap(ClientRectangle.Width, ClientRectangle.Height);
// 创建一个临时 Graphics 对象
Graphics g1 = Graphics.FromImage(curBitmap);
// 通过临时Graphics 对象绘制线条
DrawLines(g1);
// 调用Graphics 对象的DrawImage方法,并画位图
g.DrawImage(curBitmap, 0, 0);
// 释放创建的对象
g1.Dispose();
curBitmap.Dispose();
g.Dispose();
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货