如何更新部分surfaceview? [英] How to update surfaceview partially?

查看:441
本文介绍了如何更新部分surfaceview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 surfaceview 在我的活动。最初,一些圈子正在使用绘制

I have a surfaceview in my activity. Initially some circles are drawn using

Canvas c = SurfaceView.getHolder().lockCanvas();

SurfaceView.getHolder().unlockCanvasAndPost(c);

后来我想吸取 surfaceview 的一个非常小的一部分。我不想重绘整个 surfaceview 。是否有可能只更新需要的部分?

Later on I want to draw on a very small part of the surfaceview. I do not want to redraw the whole surfaceview. Is it possible to update just the required part?

推荐答案

使用 lockCanvas(矩形脏)来代替。传递要重绘的区域。

Use lockCanvas(Rect dirty) instead. Pass in the area you want to redraw.

注意是IN-OUT参数。该矩形可以扩展到覆盖更大的区域,你需要设置它涵盖了每一个像素。因此,如果(例如)SurfaceView不再具有访问previous像素,它会扩大到矩形覆盖整个表面。

Note that dirty is an in-out parameter. The Rect may be expanded to cover a larger area, and you need to set every pixel it covers. So if (for example) SurfaceView no longer has access to the previous pixels, it'll expand Rect to cover the entire surface.

由于SurfaceView是二次或三次缓冲,实现将复制像素的大块从previous缓冲区。既然你从SurfaceView得到画布是从来没有硬件加速,指定一个脏矩形往往是一个性能胜利。

Because SurfaceView is double- or triple-buffered, the implementation will copy chunks of pixels from the previous buffer. Since the Canvas you get from a SurfaceView is never hardware-accelerated, specifying a dirty rect is often a performance win.

这篇关于如何更新部分surfaceview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆