5种创建UIImage的类方法
来源:互联网 发布:如何注册两个淘宝账号 编辑:程序博客网 时间:2024/05/22 04:43
1. 使用类方法imageNamed:创建
+(UIImage *)imageNamed:(NSString *)name;
name是照片名称。创建UIImage对象 ,代码如下:
UIImage *image = [UIImage imageNamed:@"Jihong"];
使用imageNamed:初始化的时候,会先检查缓存中是否存在Jihong的照片,如果不存在,图片首先会被缓存起来,然后才返回要加载的图片对象;如果存在,直接返回要加载的照片对象。
2.使用类方法imageWithContentsOfFile:创建
+(UIImage*)imageWithContentOfFile:创建
path是需要加载照片的路径,如何获取照片的路径应该获取沙盒路径。实现代码如下:
UIImage *image = [UIImage imageWithContentOfFile:path];
使用imageWithContentOfFile:创建UIImage的时候,是直接从磁盘上加载。当收到内存警告时,UIImage对象会被释放,下一次绘图的时候,需要重新加载。
3.使用类方法imageWithData:创建
+(UIImage*)imageWithData:(NSData *)data;
data是照片数据,一般是请求返回,然后通过imageWithData:创建UIImage。实现代码如下所示:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.baidu.com/images.jpg"] ];
UIImage *image = [UIImage imageWithData:data];
4.使用类方法imageWithCGImage:创建
+(UIImage*)imageWithCGImage:(CGImageRef)cgImage;
cgImage 是定义在QuartzCore框架中的一个结构体指针。这个结构用来创建像素位图,可以通过操作存储的像素位来编辑图片
UIImage *image = [UIImage imageWithCGImage:cgImage];
5 使用类方法imageWithCIImage:创建
+(UIImage*)imageWithCIImage:(CIImage*)ciimage
CIImage 是CoreImage框架中最基本代表图像的对象,在CIImage被CIContext渲染出来之前,他是依赖于滤镜链的,滤镜是不会更改CIImage中的图像数据。
UIImage *image = [UIImage imageWithCGImage:ciImage];
以上四种方法都是UIImage的类方法,使用UIImage的初始化方法也是可以创建UIImage对象的。
- 5种创建UIImage的类方法
- 五种创建UIImage的类方法
- 五种创建UIImage的类方法
- 五种创建UIImage的类方法
- 五种创建UIImage的类方法
- iOS UIimage拉伸的三种方法
- UIImage的copy方法
- 得到UIImage的方法
- UIImage有关的几个方法
- IOS uiimage 拉伸的方法
- UILable转为UIImage的方法
- UIImage 拉伸特定的方法
- 加载UIImage的两种方法的区别
- UIImage的两种初始化方法的区别
- IOS UIImage类方法总结
- IOS UIImage类方法总结
- IOS UIImage类方法总结
- IOS UIImage类方法总结
- poj 1459
- 黑客注入之手工注入
- 例题9-11 最大面积的最小的三角剖分 UVa1331
- 数据结构之---C语言实现关键路径AOE图
- 树的共同祖先
- 5种创建UIImage的类方法
- Java开发中的23种设计模式详解(转)
- C++用多种方式实现Singleton单例模式
- atitit.javascript js 上传文件的本地预览
- std::find, std::find_if, std::find_if_not
- 构建稳定成熟的数据仓库
- Android媒体扫描代码分析
- C++编程(五)--- Cmake详解&Makefile详解
- Java DOM解析Xml中文乱码问题