需要按像素数组绘制数据(大)。我怎样才能做到这一点?
我在上面尝试了 Canvas 和 Rectangle - 计算机上吊了自己...尝试了以下选项(DrawingContext) - 计算机仍然上吊了自己,但少了一点。
请推荐计算机负载最小的选项。整数宽度 = 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);
}