initWithImage和imageWithContentsOfFile的区别

UIImageView *imageView = [[UIImageView alloc] initWithImage:

        [UIImage imageNamed:@"icon.png"]]; // 会缓存图片

UIImageView *imageView = [[UIImageView alloc] initWithImage:

        [UIImage imageWithContentsOfFile:@"icon.png"]]; // 不会缓存图片

 

application bundle的顶层文件夹寻找由供应的名字的图象。如果找到图片,装载到iPhone系统缓存图象。那意味图片是(理论上)放在内存里作为cache的。这样图片会占用大量的内存,imageWithContentsOfFile不会缓存图片,所有比较节省内存。

initWithImage和imageWithContentsOfFile的区别

时间: 2024-08-08 12:37:17

initWithImage和imageWithContentsOfFile的区别的相关文章

imageNamed 与 imageWithContentsOfFile的区别

如题,是不是大家为了方便都这样加载图片啊 myImage = [UIImage imageNamed:@"icon.png"]; 那么小心了 这种方法在一些图片很少,或者图片很小的程序里是ok的. 但是,在大量加载图片的程序里,请千万不要这样做. 为什么呢 ??????? 这种方法在application bundle的顶层文件夹寻找由供应的名字的图象 . 如果找到图片,装载到iPhone系统缓存图象.那意味图片是(理论上)放在内存里作为cache的. 试想你图片多了,是什么后果```

UIImage imageNamed 与 imageWithContentsOfFile的区别

[UIImage imageNamed:]只适合与UI界面中的贴图的读取,较大的资源文件应该尽量避免使用 用UIImage加载本地图像最常用的是下面三种: 1.用imageNamed方法 [UIImage imageNamed:ImageName]; 2.用 imageWithContentsOfFile 方法 NSString *thumbnailFile = [NSString stringWithFormat:@"%@/%@.png", [[NSBundle mainBundle

161设置在屏幕中的动画延迟(扩展知识:普通操作和代码块操作实现动画效果)

效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @property (strong, nonatomic) UIImageView *imgVAnimation; 5 6 @end ViewController.m 1 #import "ViewController.h" 2 3 @interface ViewControl

【学习ios之路:UI系列】修改图片的尺寸大小操作

1.在添加图片操作时,通过UIImage对象进行添加图片操作 1.[UIImage imageName:@"1.png"] 2.[UIImage imageWithContentsOfFile:@"1.png"] 注:ImageNamed和imageWithContentsOfFile的区别 imageNamed加载图片并缓存,并且把image缓存到内存里面,当图片较少并且会频繁的使用时用imageNamed; imageWithContentsOfFile是只显示

文件资源下载到本地后如何调用

验证方法: 1.从网络下载文件资源 2.将Zip 资源解压到Documents 3.将数据归档,并解档 NSString *filename = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)firstObject]; NSString *path = [filename stringByAppendingPathComponent:@"123"]; UIImageView

iOS开发常用的代码

%c 一个单一的字符 %d 一个十进制整数 %i 一个整数 %e, %f, %g 一个浮点数 %o 一个八进制数 %s 一个字符串 %x 一个十六进制数 %p 一个指针 %n 一个等于读取字符数量的整数 %u 一个无符号整数 %[] 一个字符集 %% 一个精度符号 //一.NSString /*----------------创建字符串的方法----------------*/ 1.创建常量字符串. NSString *astring = @"This is a String!"; 2

iOS 常识总结

1.NSCalendar用法 -(NSString *) getWeek:(NSDate *)d { NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; unsigned units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit; NSDateC

手势,轻拍(tapGesture)+轻扫(swipeGesture)

在iOS开发时我们经常用到手势,手势有很多种,先介绍两种一个轻拍(UITapGestureRecognizer)还有一个轻扫(UISwipeGestureRecognizer). 一,轻拍(UITapGestureRecognizer) 我们给图片或者一个视图添加一个点击事件,一般都用UITapGestureRecognizer,因为手势有个属性view,可以获取当前手势下的视图,运用起来非常灵活,所以我比较习惯用轻拍手势,有时候我们会纠结该用轻拍手势还是按钮,其实两者之间做选择最好的方法就是我

手势,旋转(rotationGesture)+长按(longPressGesture)

接下来讲一下旋转(UIRotationGestureRecognizer)和长按(UILongPressGestureRecognizer) 一,旋转(UIRotationGestureRecognizer) - (void)addImageViewAndAddRotationGesture { // 获取图片路径 NSString *path =[[NSBundle mainBundle] pathForResource:@"image"ofType:@"jpg"