[英]How to draw in WPF by pixel
必须按像素数组绘制数据(大)。 我怎样才能做到这一点?
我在上面尝试了一个Canvas and Rectangle-计算机上吊了自己...尝试了以下选项(DrawingContext)-计算机仍然上吊了自己,但是少了一点。
请推荐计算机上负载最少的选件。 int宽度= 800; -数组的大小(大!!!)int size = 1; -希望能够使片段不仅是一个像素,而且是几个像素
protected override void OnRender(System.Windows.Media.DrawingContext drawingContext)
{
Random rnd = new Random();
int width = 800;
int size = 1;
CellType[,] types = new CellType[width, width];
for (int i = 0; i < width; i++)
{
for (int j = 0; j < width; j++)
{
int r = rnd.Next(0, 100);
if (r >= 70) types[j,i] = CellType.IsOccupied;
else types[j, i] = CellType.IsEmpty;
}
}
for (int i = 0; i < width; i++)
{
for (int j = 0; j < width; j++)
{
Brush brush = Brushes.Black;
switch (types[j, i])
{
case CellType.IsEmpty: brush = Brushes.Green;
break;
case CellType.IsOccupied: brush = Brushes.Black;
break;
}
drawingContext.DrawRectangle(brush,
new Pen(brush, 1),
new Rect(j * size, i * size, size, size));
}
}
base.OnRender(drawingContext);
}
它冻结多长时间? 几年前,我在Silverlight中做了类似的事情。 这有点慢,但仍然可以接受。 尝试将WriteableBitmap与SetPixel或FillRectangle方法一起使用,但是请记住,在一个循环中逐像素绘制将始终需要一些时间。
忘记提及SetPixel和FillRectangle可能需要WriteableBitmapEx,可在此处获得: http : //writeablebitmapex.codeplex.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.