当我们是一家人View  多于UIImageView,和UIImageView表明一个更大的HD,可能存在的存储器的警告的问题。假设第一次走进这个view,无记忆出现预警。当重新进入view,在那曾经的记忆不及时释放的假设。这是蓄积的经时,它可以导致内存破坏。

1,UIImage 载入图片的方式。

假设是本地图片,尽量不要使用 [UIImage  imageNamed:nil]; 这样的方式,假设使用这样的方式载入。仅仅要程序不退出,它便一直会在内存中。

我们能够使用 :

  NSString *path = [[NSBundlemainBundle]pathForResource:@'"图片的名字" ofType:@""];

                        UIImage *image = [UIImageimageWithContentsOfFile:path];



         那两者的优缺点就非常明显了,[UIImage  imageNamed:nil]; 仅仅需载入一次,它便在内存中,所以第二次载入速度非常快。而另外一种载入方式因为我们将它释放掉了,会再次载入。

所以选用那种方式,依你情况而定。

2,上面说的另外一种方式。尽管能够释放掉,但我们要告诉人家什么时候释放。也就是说,当前显示页面不是这个view时,我们便将它释放掉:

- (void)viewWillDisappear:(BOOL)animated{

[UIImageView removeFromSuperview];

UiImageView = nil;

}

当然,当我们再次进入这个view时,便要将移除掉的view再次加入进来

- (void)viewDidAppear:(BOOL)animated{

[self addSubView:UIImageView];

}

3,上述两种方式。主要解决内存累加的问题。但假设第一次进入view。图片所有渲染在view上时。内存就崩溃了。

那我们仅仅能在图片上做文章了。我们载入的高清大图假设差点儿相同都是3000*2000,也可能比这个还大,就算我们的程序是iPad App,iPad 4  的分辨率才多少。这些图远远大于设备的分辨率,全然是资源浪费,所以我们通常的一个做法,便是将这种图以小尺寸渲染到view上。



推荐使用:

UIImage+Resize.hUIImage+Resize.m
Extends the UIImage class to support resizing (optionally preserving the original aspect ratio), cropping, and generating thumbnails.

url=F4ENFVFHF5GSGDEKEIFXE2F5FJEODYDGE2FBE3F4E5FOD7EBD0C6DNDTEBEBD0DXFFENEDE6FPGIEWEKEUGAEZGPFHGIEWC3GMGQEEEYGNF2E4EOERF8GFF1GJFXDZF4GPF1DZETGAEZFUFDEVCZDKDVFKFMGBF0" style="padding:1px 0px; margin:0px; color:rgb(119,119,119); text-decoration:none; border-bottom-width:1px; border-bottom-style:solid; border-color:rgb(187,187,187)">UIImage+RoundedCorner.h

url=F9ENFVFHF5GSGDEKEIFXE2F5FJEODYDGE2FBE3F4E5FOD7EBD0C6DNDTEBEBD0DXFFENEDE6FPGIEWEKEUGAEZGPFHGIEWC3GMGQEEEYGNF2E4EOERF8GFF1GJFXDZF4GPF1DZETGAEZFUFDEVCZDKDVFKFMGBF0" style="padding:1px 0px; margin:0px; color:rgb(119,119,119); text-decoration:none; border-bottom-width:1px; border-bottom-style:solid; border-color:rgb(187,187,187)">UIImage+RoundedCorner.m

Extends the UIImage class to support adding rounded corners to an image.

UIImage+Alpha.hUIImage+Alpha.m
Extends the UIImage class with helper methods for working with alpha layers (transparencies).


经常用法:

UIImage *image

UIImage *thumbImage = [imagethumbnailImage:140//
This should the size of the view in collection view. example: myCell width is 20 and height is 20.

transparentBorder:0

cornerRadius:0

interpolationQuality:kCGInterpolationMedium];       //生成缩略图

// this "resizedimage" image is what you want to pass to setImage

UIImage * resizedImage = [imageresizedImage:imageview.frame.sizeinterpolationQuality:
kCGInterpolationLow];   //生成你想要尺寸的图

造成的问题,要注意缩放的比例,不要导致图片变形,因为尺寸缩小,可能会导致图片模糊,注意缩小的尺寸。

综上可见。每种方法有长处,有缺点。主要根据自己的开发情况,用妥协。

版权声明:本文博客原创文章。博客,未经同意,不得转载。

最新文章

  1. 打印IP 来源
  2. Django根据现有数据库建立model
  3. HIS-DELPHI-读取数据库配置
  4. HTTP和FTP的区别
  5. jszs 快速排序
  6. UVaLive 7371 Triangle (水题,判矩形)
  7. Cppcheck代码分析(1)
  8. 【转】WPF中的Binding技巧(二)
  9. 如何用 React Native 创建一个iOS APP?(三)
  10. 关于int全区变量读写的原子性
  11. invalid stream header: 31323334
  12. 如何判断Linux 是32位还是64位
  13. MongoDB查询分析
  14. windows平台下python 打包成exe可执行文件
  15. 百度编辑器ueditor
  16. 登录功能(MD5加密)
  17. Leetcode:Two Sum
  18. 【搬运工】mysql用户权限设置
  19. .net 语音,视频等格式转换
  20. react-eslintrc

热门文章

  1. c++野指针 之 实战篇
  2. html网页特殊符号代码
  3. Delphi F11 全屏
  4. 在Eclipse在使用JUnit4单元测试(0基础知识)
  5. Centos 6.4 Linux 相关问题总结
  6. Bestcoder Round#45
  7. poj1364(差分约束系统)
  8. 【译】手动处理Team Foundation Server 2010 数据仓库和分析服务数据库
  9. petshop4.0 其中详细解释(系统架构)
  10. ICTCLAS用的字Lucene4.9捆绑