在uiimageview中加载大图像时的内存消耗 [英] Memory consumption while loading a large image in uiimageview in

查看:703
本文介绍了在uiimageview中加载大图像时的内存消耗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用UIViewContentModeScaleAspectFit将大小为2480×3508的UIImage加载到UIImageView中。我在加载此图像时收到内存警告。在我在这个UIImageView中加载了一些这样大小的图像后,应用程序崩溃了。有没有办法解决这个问题。

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)或者您可以选择显示它在CATiledLayer(* 2)的帮助下全分辨率。

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示例

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

附录:如果您的图像源是照片库,ALASSet会将已缩放的图像提供给全屏和全分辨率图像。您可以将两者结合使用CATiledLayer。全屏图像被添加到CATiledLayer下面的图层,以作为占位符,同时等待CATiledLayer中的图块加载。

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.

这篇关于在uiimageview中加载大图像时的内存消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆