使用具有“不透明”属性的图像可以获得更好的性能。财产?为什么?
我刚刚在该网站上找到了一些内容:iphoneexamples.com。 看着“显示图像”,我发现了一些新东西。
myImage.opaque = YES; // 对于性能来说明显不透明
有人可以向我解释一下吗?它适用于哪种类型(或用例)的图像?什么时候不呢? 很高兴知道。感谢您抽出时间...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
iPhone GPU 是基于图块的渲染器。如果覆盖层在整个图块上完全不透明,则 GPU 可以忽略设置和处理与该特定图块下面的层相关的任何图形命令,并且不必对该图块中的像素进行合成。
如果您的图像没有覆盖完整的图块,GPU 仍然需要处理多个层。图块的大小取决于实现,但是微小的图形图像覆盖图块的可能性要小得多。覆盖多个图块的巨大图像将显示出不透明的最大优势。
The iPhone GPU is a tile-based renderer. If an overlaying layer is completely opaque over an entire tile, the GPU can ignore setting up and processing any graphics commands related to the layer underneath for that particular tile, in addition to not having to do compositing of the pixels in that tile.
If your image doesn't cover a complete tile, the GPU will still have to potentially process multiple layers. The size of a tile is implementation dependent, but tiny graphics images are far less likely to cover a tile. Huge images that cover multiple tiles will show the greatest advantage from being opaque.
来自查看 iOS 编程指南:
hotpaw2 指出了其幕后原因,可以在 iOS 版 OpenGL ES 编程指南:
From the View Programming Guide for iOS:
hotpaw2 points out the behind-the-scenes reason for this, which can be found in the OpenGL ES Programming Guide for iOS:
当视图或图层不透明时,您可以获得比不透明时更好的性能。如果它不是不透明的,图形系统必须将该层与下面的层合成以生成最终图像。如果它是不透明的,那么只需将像素复制到帧缓冲区即可。
You get better performance when a view or layer is opaque than when it's not. If it's not opaque, the graphics system has to composite that layer with the layers below to produce the final image. If it is opaque, then it's just a matter of copying the pixels to the frame buffer.
需要注意的一个棘手问题是,每当图像属性更改为新的 UIImage 时,UIImageView 都会将 opaque 属性重置为 FALSE。您可以显式签入代码并在对图像属性进行任何更改后设置不透明属性,或者您可以扩展 UIImageView 并提供自己的 setImage 实现,该实现在调用超级 setImage 方法后设置不透明。我只是偶然才知道这件事。
A little tricky issue to be aware of is that UIImageView will reset the opaque property to FALSE any time the image property is changed to a new UIImage. You could explicitly check in your code and set the opaque property after any change to the image property, or you could extend UIImageView and provide you own implementation of setImage that sets opaque after calling the super setImage method. I only found out about this by accident.