image size for UIImages, 1024 x 1024?

前端 未结 1 1056
栀梦
栀梦 2021-01-05 22:40

Apples docs state:

You should avoid creating UIImage objects that are greater than 1024 x 1024 in size. Besides the large amount of memory such an i

相关标签:
1条回答
  • 2021-01-05 23:33

    On the pre-A5 iOS devices, the maximum OpenGL ES texture size was 2048x2048 (Apple's documentation is incorrect in this regard by saying it's 1024x1024). What that means is that you can't have an image larger than that in either dimension. The newer iOS devices (iPhone 4S, iPad 2, iPad 3) have a maximum texture size of 4096x4096.

    It does not mean that you have to have square images, just that an image must not have its width or height exceed 2048 (again, 4096 on newer devices). If you try to do so, I believe your image will just render as black.

    This used to be a limitation for all UIViews not backed by a CATiledLayer, but I believe they now do tiling on large enough views automatically. If you need to work with an image larger than 2048x2048, you'll need to host it in a CATiledLayer or the like.

    The memory cautions are worth paying attention to, though. Images are stored in their uncompressed form in memory, no matter their source, so you're looking at 16,777,216 bytes per 2048x2048 image (4 bytes per pixel for RGBA). That can add up pretty quickly, if you're not careful.

    0 讨论(0)
提交回复
热议问题