UIImage加载图片的几种方式

来源:互联网 发布:炉石传说 mac 花屏 编辑:程序博客网 时间:2024/04/27 18:51

1、

[UIImage imageNamed:@"picName"]

以这种方式加载图片,从第一张图片浏览到最后一张图片时,内存变化如图所示:

刚开始:

图片加载一遍后:

可以看到内存占用直线上升。当然这种方式也是有好处的,下次加载时由于已经在内存中,所以速度很快。

2、

NSString * picPath = [[NSBundle mainBundle] pathForResource:@"jpgPath" ofType:@"jpg"];_imageView.image = [[UIImage alloc] initWithContentsOfFile:picPath];

以这种方式加载图片,从第一张图片浏览到最后一张图片时,内存变化如图所示:

刚开始:

图片加载一遍:

可以看到内存变化不是很明显。这种方式每次都需要重新加载,速度自然没有第一种方式快。

3、

NSString * picPath = [[NSBundle mainBundle] pathForResource:@"jpgPath" ofType:@"jpg"];NSData * picData = [NSData dataWithContentsOfFile:picPath];_imageView.image = [UIImage imageWithData:picData];
刚开始:

浏览一遍之后:

有图片可看到,此种方式对内存的影响也不大。





0 0
原创粉丝点击