用什么在Android的绘图 - 查看或SurfaceView? [英] What to use for drawing in Android - View or SurfaceView?

查看:131
本文介绍了用什么在Android的绘图 - 查看或SurfaceView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

小开场白: 我创建一个某种形式的针对Android绘图程序中(API 14及更高版本)。几个月前,我已经开始做这个工作,并决定使用SurfaceView作为画布上绘制。我认为这一个很好的决定的原因 SurfaceView 与图形工作直接。一切似乎很好地工作,直到有一天我发现绘制过程是有点laggy。这里很可能有很多奇怪的code的出现了下滑。

反正现在我是优化code之类的东西,我想,我真的需要使用SurfaceView这样的情景?我从我的画布,需要的主要事情是为画流畅并能够保存所有的图纸Bitmap->在外部存储文件(这工作正常)。

Anyway, now I'm optimizing that code and stuff, and I thought, do I really need to use SurfaceView for such scenario? The main things I need from my "canvas" is to draw smooth and be able to save all the drawings to Bitmap->File on External storage (this works fine).

所以,我应该用简单的查看 SurfaceView ?此外,这将是伟大听到你的决定/命题的道具和缺点。

So, should I use the simple View or the SurfaceView? Also, it would be great to hear props and cons of your decision/proposition.

感谢

推荐答案

如果你想使用画布,你是越来越多地与自定义视图,而不是SurfaceView更好。原因很简单,就是画布上呈现一个视图可以硬件加速,而画布上绘制一个SurfaceView的表面软件经常做(尚真为的是Android 5.0的)。

If you want to use Canvas, you are increasingly better off with a custom View, rather than a SurfaceView. The simple reason is that Canvas rendering on a View can be hardware accelerated, while Canvas rendering on a SurfaceView's surface is always done in software (still true as of Android 5.0).

通过绘制平稳我想你想要一些反锯齿效果。检查硬件加速页的表格,以确认您想要的效果都支持Android的发布要出货的。

By drawing "smooth" I assume you want some anti-aliasing effects. Check the chart on the hardware acceleration page to confirm that the effects you want are supported for the Android releases you want to ship on.

随着设备的显示像素数量得到稳步走高,软件渲染变得越来越昂贵,而且在某些设备上的CPU或公交车是不是足够快,以保持帧速率高。幸运的是这些像素密度是如此之高,你并不真的需要抗锯齿,所以即使它不支持,你可以忽视它,直到你生成软件渲染的位图。

As device display pixel counts get steadily higher, software rendering gets increasingly expensive, and on some devices the CPU or bus isn't fast enough to keep frame rates high. Fortunately on these the pixel density is so high that you don't really need anti-aliasing, so even if it's not supported you could ignore it until you generate your software-rendered bitmap.

在你做任何事情,不过,这将是明智的,找出你懈怠的来源是什么。这是可能你正在绘图code,而不是像素填充率放缓由低效率。与一些分析工具检查一下。

Before you do anything, though, it would be wise to figure out what your source of sluggishness is. It's possible you're being slowed down by inefficiencies in your drawing code rather than pixel fill rate. Check it with some of the profiling tools.

(另见图形架构文档。)

这篇关于用什么在Android的绘图 - 查看或SurfaceView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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