Memory consumption while loading a large image in uiimageview in

浪子不回头ぞ 提交于 2019-12-23 04:34:43

问题


I am loading a UIImage of size 2480 × 3508 into UIImageView using UIViewContentModeScaleAspectFit. I am getting memory warning while loading this image. And after i loaded a few images of this size in this UIImageView the application crashes. Is there any method to solve this.


回答1:


Solution to this problem consists of either loading scaled version of the image (*1) or you have option to display it in full resolution with help of CATiledLayer(*2).

  1. [UIImage imageWithCGImage:scale:orientation:];
  2. CATiledLayer example

Addendum: If your image source is Photo Library, ALASSet provides already scaled image to full screen and full resolution image. You can use combination of both with CATiledLayer. Full screen image is added to layer beneath the CATiledLayer to serve as placeholder while you're waiting for tiles in CATiledLayer to load.




回答2:


Well, according to the documentation :

You should avoid creating UIImage objects that are greater than 1024 x 1024 in size.

Reduce your image then load it in your ImageView, there are plenty of libraries to do this, here is one :

https://github.com/Nyx0uf/NYXImagesUtilities




回答3:


You can use this for scaling The method is described simply in the following link:

How to scale a UIImageView proportionally?



来源:https://stackoverflow.com/questions/6110637/memory-consumption-while-loading-a-large-image-in-uiimageview-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!