Memory consumption while loading a large image in

2019-06-01 01:04发布

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.

3条回答
一夜七次
2楼-- · 2019-06-01 01:12

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.

查看更多
▲ chillily
3楼-- · 2019-06-01 01:22

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

How to scale a UIImageView proportionally?

查看更多
三岁会撩人
4楼-- · 2019-06-01 01:26

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

查看更多
登录 后发表回答