在另一个图像上绘制图像的最快方法是什么?
我有 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.
我将在bottomLayer上绘制复杂的背景。 我不想一次又一次地在totalCanvas上重绘复杂的背景,所以我将它存储在bottomLayer中。
TopLayer经常更改。 我想将bottomLayer绘制到totalCanvas。 哪种方法最快?
Graphics canvas(totalCanvas);
canvas.DrawImage(bottomLayer, 0, 0); step1
canvas.DrawImage(topLayer ,XXXXX); step2
我希望步骤 1 尽可能快。 谁能给我一些样品吗? 非常感谢!
感谢放松的回答。 我编写了以下代码:
Graphics canvas(totalCanvas);
for (int i = 0; i < 100; ++i)
{
canvas.DrawImage(bottomLayer, 0,0);
}
这部分需要 968ms...太慢了...
I have 3 Bitmap point .
Bitmap* totalCanvas = new Bitmap(400, 300, PixelFormat32bppARGB); // final canvas
Bitmap* bottomLayer = new Bitmap(400, 300,PixelFormat32bppARGB); // background
Bitmap* topLayer = new Bitmap(XXX); // always changed.
I will draw complex background on bottomLayer. I don't want to redraw complex background on totalCanvas again and again, so I stored it in bottomLayer.
TopLayer changed frequently.
I want to draw bottomLayer to totalCanvas. Which is the fastest way?
Graphics canvas(totalCanvas);
canvas.DrawImage(bottomLayer, 0, 0); step1
canvas.DrawImage(topLayer ,XXXXX); step2
I want step1 to be as fast as possible. Can anyone give me some sample?
Thanks very much!
Thanks for unwind's answer. I write the following code:
Graphics canvas(totalCanvas);
for (int i = 0; i < 100; ++i)
{
canvas.DrawImage(bottomLayer, 0,0);
}
this part takes 968ms... it is too slow...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果可能的话(从代码中看起来是这样),使用 DrawImageUnscaled 将比 DrawImage 快得多。 或者,如果您一遍又一遍地使用同一图像,请创建一个TextureBrush并使用它。
GDI+ 的问题是,在大多数情况下,它是不加速的。 为了获得闪电般的快速绘制速度,您确实需要 GDI 和 BitBlt,但与 GDI+ 一起使用时这是一个严重的痛苦,特别是如果您使用托管代码(很难判断您使用的是托管 C++ 还是直接 C++)。
请参阅此帖子,了解有关 .net 中图形快速处理的更多信息。
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.