加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – UIImages的图像大小,1024 x 1024?

发布时间:2020-12-14 17:59:54 所属栏目:百科 来源:网络整理
导读:苹果文档声明: You should avoid creating UIImage objects that are greater than 1024 x 1024 in size. Besides the large amount of memory such an image would consume,you may run into problems when using the image as a texture in OpenGL ES or
苹果文档声明:

You should avoid creating UIImage objects that are greater than 1024 x
1024 in size. Besides the large amount of memory such an image would
consume,you may run into problems when using the image as a texture
in OpenGL ES or when drawing the image to a view or layer. This size
restriction does not apply if you are performing code-based
manipulations,such as resizing an image larger than 1024 x 1024
pixels by drawing it to a bitmap-backed graphics context. In fact,you
may need to resize an image in this manner (or break it into several
smaller images) in order to draw it to one of your views.

我认为这意味着如果我们使用非方形图像,我们应该将它们分解成更小的图像?是否有任何具体的文件或解释,或者有任何经验提示吗?

谢谢阅读.

解决方法

在A5之前的iOS设备上,最大的OpenGL ES纹理大小为2048×2048(Apple的文档在这方面不正确,称其为1024×1024).这意味着你不能拥有比任何一个维度更大的图像.较新的iOS设备(iPhone 4S,iPad 2,iPad 3)的最大纹理尺寸为4096×4096.

这并不意味着您必须拥有方形图像,只是图像的宽度或高度不得超过2048(在新设备上再次为4096).如果您尝试这样做,我相信您的图像将呈现为黑色.

这曾经是所有没有CATiledLayer支持的UIViews的限制,但我相信他们现在会自动对足够大的视图进行平铺.如果您需要使用大于2048×2048的图像,则需要将其托管在CATiledLayer等中.

但记忆警告值得关注.图像以未压缩的形式存储在内存中,无论其来源如何,因此您需要查看每2048×2048图像16,777,216个字节(RGBA每像素4个字节).如果你不小心,这可以很快加起来.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读