Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

image size for UIImages, 1024 x 1024?

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 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.

I assume this means that if we are working with non-square images, we should break them into smaller images? Is there any specific documentation or explanations on this, or does anyone have any any tips from experience?

Thanks for reading.

like image 958
Mr Ordinary Avatar asked Aug 20 '12 02:08

Mr Ordinary


1 Answers

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.

like image 173
Brad Larson Avatar answered Sep 19 '22 01:09

Brad Larson