Why does my UIImage take up so much memory?

后端 未结 3 1453
夕颜
夕颜 2021-01-02 13:25

I have a UIImage that I\'m loading into one of my app\'s views. It is a 10.7 MB image, but when it loads in the app, the app\'s resource usage suddenly jumps by 50 MB. Why

3条回答
  •  萌比男神i
    2021-01-02 13:57

    No, it should not be 10.7MB. The 10.7MB is the compressed size of the image. The image loaded in to the UIImage object is a decoded image.

    For each pixel in the image 4 bytes (R,G,B and Alpha) are used, therefore you can calculate the memory size, height x width x 4 = total bytes in memory.

    So the moment you loaded the image into memory it will take up lots of memory, and since a UIImageView is used to present the image and as a subview the images is kept in memory.

    You should try and change the size of the image to match the size of the iOS screen size.

提交回复
热议问题