0

我有 3 个位图点。

Bitmap* totalCanvas = new Bitmap(400, 300, PixelFormat32bppARGB);  // final canvas
Bitmap* bottomLayer  = new Bitmap(400, 300,PixelFormat32bppARGB); // background
Bitmap* topLayer = new Bitmap(XXX); // always changed. 

我将在底部图层上绘制复杂的背景。我不想一次又一次地在totalCanvas上重绘复杂的背景,所以我把它存储在bottomLayer中。

TopLayer 经常更改。我想将bottomLayer 绘制到totalCanvas。哪种方式最快?

Graphics canvas(totalCanvas); 
canvas.DrawImage(bottomLayer, 0, 0);  step1
canvas.DrawImage(topLayer ,XXXXX);   step2

我希望 step1 尽可能快。谁能给我一些样品?非常感谢!

感谢您放松的回答。我写了以下代码:

Graphics canvas(totalCanvas); 
for (int i = 0; i < 100; ++i)
{
canvas.DrawImage(bottomLayer, 0,0);
}

这部分需要 968 毫秒……太慢了……

4

2 回答 2

1

If at all possible (and it looks like it from your code), using DrawImageUnscaled will be significgantly faster than DrawImage. Or if you are using the same image over and over again, create a TextureBrush and use that.

The problem with GDI+, is that for the most part, it is unaccelerated. To get the lightening fast drawing speeds you really need GDI and BitBlt, which is a serious pain in the but to use with GDI+, especially if you are in Managed code (hard to tell if you are using managed C++ or straight C++).

See this post for more information about graphics quickly in .net.

于 2009-04-18T16:27:45.960 回答
1

几乎所有的 GDI+ 操作都应该由驱动程序实现,以尽可能在 GPU 上运行。这应该意味着一个简单的 2D 位图复制操作将“足够快”,即使是“足够”的相当大的值。

我的建议是显而易见的:不要花时间寻找一种“最快”的方式来做这件事。您已经非常清楚地阐述了问题,所以只需按照您在问题中概述的方式尝试清楚地实施它。然后,您当然可以继续进行基准测试并决定继续寻找。

一个简单的例子:

32 bpp 400x300 位图的大小约为 469 KB。根据这张方便的表格,2002 年的 Nvidia GeForce 4 MX 的理论内存带宽为 2.6 GB/s。假设复制是在纯“覆盖”模式下完成的,即没有混合现有表面(听起来不错,因为您的复制基本上是一种将帧“清除”到副本源数据的方式),并且开销因子为四为了安全起见,我们得到:

(2.6 * 2^30 / (4 * 469 * 2^10)) = 1453

这意味着您的副本应该以 1453 FPS 运行,我很高兴地认为它“足够好”。

于 2009-04-15T08:42:06.917 回答