如何优化Android上的Canvas绘图-drawBitmap?

发布于 2024-10-05 03:28:44 字数 483 浏览 4 评论 0原文

我已经完成了我的分析,似乎我的大部分时间都花在了drawBitmap 期间,它在每一帧上被调用(可以理解)。

我使用 SurfaceView/更新线程/画布锁定方法,如 LunarLander 示例中所示。但我已经改变了它(根据这个问题)关于

  • 在第一帧上构造一个位图缓冲区并在其上绘制
  • ,在每个帧的末尾重用该位图绘制每个后续帧(并非屏幕上的所有内容都发生变化),
  • 将缓冲区绘制到目标画布中一次(对着屏幕)

Traceview 向我显示,在我的 800x480 设备上,此绘制位图每帧需要 5 毫秒。我能得到比这更好的东西吗?还是它只是“刻在石头上”的东西,我只需要优化代码的其他部分即可实现良好的每秒帧数?

I've done my profiling and it seems that most of my time is spent during drawBitmap, which is called (understandingly) on every frame.

I use SurfaceView/updating thread/canvas locking approach as demonstrated in LunarLander sample. But I've changed it (according to this question) as to

  • on the very first frame construct a bitmap buffer and paint onto it
  • paint each subsequent frame reusing that Bitmap (not everything on my screen changes)
  • at the end of each frame paint the buffer once into the target Canvas (to the screen)

Traceview showed me that this drawBitmap takes 5ms for each frame on my 800x480 device. Can I get any better than that or is it just something that is 'carved into the stone' and I just have to optimize other parts of the code to achieve good frames per second?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇纵 2024-10-12 03:29:12

有一场关于最快绘图库的竞赛... libgdx 目前获胜...示例应用程序也像您一样使用 800x480。

http://code.google.com/p/libgdx/wiki/SimpleApp#Project_Setup

there is a competition running for the fastest drawing library... libgdx is currently winning... the sample apps also use 800x480 just like you are.

http://code.google.com/p/libgdx/wiki/SimpleApp#Project_Setup

煮茶煮酒煮时光 2024-10-12 03:29:00

这取决于很多因素,但通常 drawBitmap() 会尽可能快。在您的特定情况下,如果您不需要混合,请确保您使用的是不透明位图。此外,尝试使用与 Surface 兼容的格式的位图。例如,如果您使用的是 16 位 Surface,则绘制 16 位 (RGB565) 位图将非常快(这只是 memcpy 调用。)如果您的 Surface 是 32 位,请使用 ARGB8888 不透明位图。

It depends on many things, but usually drawBitmap() will be as fast as it can get. In your particular case, if you don't need blending, make sure your are using an opaque bitmap. In addition, try to use a Bitmap in a format compatible with your Surface. For instance, if you are using a 16 bits Surface, drawing a 16-bits (RGB565) bitmap will be very fast (it's just a memcpy call.) If your Surface is 32 bits, use an ARGB8888 opaque Bitmap.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文