iPhone的性能差异在石英绘图与预烘焙的图像(我猜,简化为Quartz与石英) [英] iPhone Performance Differences in Quartz Drawing vs. Pre-Baked Images (which I guess simplifies to Quartz vs. Quartz)

查看:169
本文介绍了iPhone的性能差异在石英绘图与预烘焙的图像(我猜,简化为Quartz与石英)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新到Quartz,我很好奇简单的形状,渐变和阴影的绘制速度;特别是将Quartz绘图函数与iPhone上的Quartz图像绘图进行比较。

New to Quartz and I am curious on the drawing speeds of simple shapes, gradients, and shadows; specifically comparing Quartz drawing functions to Quartz image drawing on the iPhone.

说我需要绘制一个填充,描边和阴影的矩形。我假设导入一个预烘焙的矩形作为PNG和绘制它使用drawInRect:或drawAtPoint:比使用Quartz的绘图函数来绘制相同的东西,因为后者需要显式计算。另一方面,绘制图像我假设增加了内存使用和应用程序大小,因为我必须导入图像,然后分配它。这是否正确?

Say that I need to draw a filled, stroked, and shadowed rectangle. I'm assuming that importing a pre-baked rect as a PNG and drawing it using drawInRect: or drawAtPoint: is faster than using Quartz's drawing functions to draw the same thing, since the latter requires explicit calculations. On the other hand, drawing an image I assume increases memory use and application size since I have to import the image and then alloc it. Does this sound right?

除此之外,这两种技术有什么大的优点/缺点吗?作为一个非常熟悉图形程序和全新的Quartz,我试图决定是否有任何优势,使用我的代码中的绘图功能,而不是预烘焙整个UI和导入图像。

Besides that, are there any big advantages/disadvantages to either technique? As someone who is very familiar with graphics programs and brand new to Quartz, I'm trying to decide if there are any advantages to using the drawing functions in my code as opposed to pre-baking the entire UI and importing the images.

推荐答案

我有一个类似的问题,所以我超时了不同的方法。在大多数简单的绘图情况下(如矩形示例),从磁盘加载图像似乎比绘图慢一些,可能是由于需要磁盘访问。在这些情况下,我已经决定使用Quartz绘图程序,只是因为它们给我的灵活性。如果我想在将来更改UI元素的大小(可能支持更大或更高分辨率的显示),我需要重新渲染我的所有图像,矢量绘图将根据需要缩放。

I had a similar question, so I timed out the different approaches. In most simple drawing cases (like your rectangle example), loading an image from disk seemed to be slightly slower than drawing one, perhaps due to the disk access required. In those cases, I've settled on using the Quartz drawing routines, simply because of the flexibility they give me. If I want to change the size of a UI element in the future (maybe to support a larger or higher resolution display), I would need to re-render all of my images, where the vector drawings will scale as needed.

我看到一个重大的性能胜利的一个领域是我绘制作为背景的大径向渐变。在Shark中,我可以看到CGContextDrawRadialGradient()调用正在咀嚼很多CPU时间。当我用静态图像替换石英绘制的放射渐变时,我看到应用程序启动时间明显减少(这个背景是在应用程序启动时放置的)。奇怪的是,我还看到应用程序内存使用减少了大约0.5 MB,我不能完全解释。

One area where I did see a significant performance win is for a large radial gradient that I draw as a background. In Shark, I could see that the CGContextDrawRadialGradient() call was chewing up a lot of CPU time. When I replaced the Quartz-drawn radial gradient with a static image, I saw a noticeable reduction in application startup time (this background is placed during application startup). Oddly, I also saw a reduction in application memory usage by about 0.5 MB, which I can't fully explain.

如果你想自己测试,我强烈推荐拾取图片编辑器 Opacity ,它可以为图形生成Quartz代码(包括完整的UIView或CALayer子类),以及输出该相同图形的PNG。这使得在您的应用程序中实现这两个路径并测试它们非常简单。

If you want to test this yourself, I highly recommend picking up the image editor Opacity, which can generate Quartz code for a drawing (including a full UIView or CALayer subclass), as well as output a PNG of that same drawing. This makes it trivial to implement both paths within your application and test them out.

这篇关于iPhone的性能差异在石英绘图与预烘焙的图像(我猜,简化为Quartz与石英)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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