Android 上的 Java 中使用画布和 SurfaceView 的双缓冲
如何去做这件事呢?有人能给我一个大纲吗?
从我在网上找到的内容来看,在我的 run() 函数中似乎是这样的:
- 创建一个位图
- 创建一个画布并将其附加到位图
- lockCanvas()
- 调用draw(canvas)并将位图绘制到后台缓冲区中(如何??)
- unlockCanvasAndPost ()
这是正确的吗?如果是这样,我能得到一些解释吗?这些步骤意味着什么以及如何实施它们?我以前从未为 Android 编程过,所以我是一个真正的菜鸟。如果不正确,我该怎么做?
How does one go about doing this? Could somebody give me an outline?
From what I've found online, it seems like in my run() function:
- create a bitmap
- create a canvas and attach it to the bitmap
- lockCanvas()
- call draw(canvas) and draw bitmap into back buffer (how??)
- unlockCanvasAndPost()
Is this correct? If so, could I get a bit of an explanation; what do these steps mean and how do I implement them? I've never programmed for Android before so I'm a real noob. And if it isn't correct, how DO I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它已经是双缓冲的,这就是unlockCanvasAndPost() 调用的作用。无需创建位图。
It's already double buffered, that's what the unlockCanvasAndPost() call does. There is no need to create a bitmap.
Android 开发者小组中的步骤表明您需要一个缓冲区 -画布,所有渲染都绘制到上面。
您将获得主缓冲区,您正在绘制该缓冲区,而无需在每个持有者的锁上获得不同的双缓冲区画布。
The steps from Android Developers Group say that you need a buffer-canvas, to which all the renders are drawn onto.
You are getting the main buffer, which you are drawing into without getting different double-buffer canvas' on each holder's lock.