
本文介绍了提高绘制在WPF瓷砖位图的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在寻找改善一些绘图我做的性能的方式。目前,它是瓷砖的32×32格,我画画。使用下面的代码绘制到图纸背景
的for(int x = startx的; X< endX; X ++)
{
为(INT Y = startY; Y<恩迪; Y ++)
{
dg.Children.Add(
新ImageDrawing(_mapTiles [GameWorldObject.GameMap [X ,Y] .GraphicsTile.TileStartPoint],
新的矩形(CountX * 8 *郡8,8,8)
));
dg.Children.Add(
新GeometryDrawing(
空,
新朋(
新的SolidColorBrush(
Color.FromRgb(255 ,0,20)),0.3),
新RectangleGeometry(
新的Rect(CountX * 8,郡* 8,8,8)$ b $二)$ b $二)
);
县++;
}
县= 0;
CountX ++;
}
dc.DrawDrawing(DG);
我绘制的图像,是一个CachedBitmap。即使使用CachedBitmap,我还有第二个我每次需要重新绘制画布约一半的延迟。
不知道是否有处理更高性能的方式绘图该网格。最后,我想扩大控制功能迷你地图,所以我需要记住这一点。
另外,我想以前只是直接绘制每个位图绘图环境,但似乎有点慢。
解决方案 我画前加入DrawingGroup.Freeze(),它似乎帮助的表现
。
I'm looking for a way to improve the performance of some drawing I am doing. Currently it is a 32x32 grid of tiles that I am drawing. Using the following code to draw onto the drawing context
for (int x = startX; x < endX; x++)
{
for (int y = startY; y < endY; y++)
{
dg.Children.Add(
new ImageDrawing(_mapTiles[GameWorldObject.GameMap[x, y].GraphicsTile.TileStartPoint],
new Rect(CountX * 8, CountY * 8, 8, 8)
));
dg.Children.Add(
new GeometryDrawing(
null,
new Pen(
new SolidColorBrush(
Color.FromRgb(255, 0, 20)), .3),
new RectangleGeometry(
new Rect(CountX * 8, CountY * 8, 8, 8)
)
)
);
CountY++;
}
CountY = 0;
CountX++;
}
dc.DrawDrawing(dg);
The Image I am drawing is a CachedBitmap. Even using a CachedBitmap, I still have a delay of about a half second each time I need to redraw the Canvas.
Not sure if there is a more performant way to handle drawing to this grid. Eventually I want to expand control to function as a mini-map, so I need to keep that in mind.
Also, I tried previously to just draw each bitmap directly to the drawing context but that seems a bit slower.
解决方案
I added DrawingGroup.Freeze() before drawing, and it seemed to help with the performance.
这篇关于提高绘制在WPF瓷砖位图的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-05 13:47