问题
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).
- [UIImage imageWithCGImage:scale:orientation:];
- 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