五种创建UIImage的类方法
来源:互联网 发布:新手音乐制作软件 编辑:程序博客网 时间:2024/06/15 01:50
文/李刚(简书作者)
原文链接:http://www.jianshu.com/p/69f08e0cd49b
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
1.使用类方法
2.使用类方法
3.使用类方法
4.使用类方法
5.使用类方法
原文链接:http://www.jianshu.com/p/69f08e0cd49b
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
UIImage
有五个类方法,用来创建UIImage
的。下面介绍一下每个类方法的作用和创建实例。
1.使用类方法imageNamed:
创建
+ (UIImage *)imageNamed:(NSString *)name; // load from main bundle
name
是照片名称。创建UIImage对象,代码如下:
UIImage *image = [UIImage imageNamed:@"ganggang"];
使用imageNamed:
初始化的时候,会先检查缓存中是否存在ganggang
的照片,如不存在,图片首先会被缓存起来,然后才返回要加载的图片对象;如果存在,直接返回要加载的照片对象。
2.使用类方法imageWithContentsOfFile:
创建
+ (UIImage *)imageWithContentsOfFile:(NSString *)path;
path
是需要加载照片的路径,如何获取照片的路径请点击iOS开发之获取沙盒路径。实现代码如下:
UIImage *image = [UIImage imageWithContentsOfFile:path];
使用imageWithContentsOfFile:
创建UIImage
的时候,是直接从磁盘上加载。当收到内存警告时,UIImage
对象会被释放,下一次绘图的时候,需要重新加载。
3.使用类方法imageWithData:
创建
+ (UIImage *)imageWithData:(NSData *)data;
data
是照片数据,一般是请求返回的,然后通过imageWithData:
创建UIImage
。实现代码如下所示:
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.superqq.com/images/getqrcode.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 NS_AVAILABLE_IOS(5_0);
CIImage
是CoreImage
框架中最基本代表图像的对象,在CIImage
被CIContext
渲染出来之前,他是依赖于滤镜链的,滤镜是不会更改CIImage
中的图像数据。
UIImage *image = [UIImage imageWithCGImage:ciImage];
以上四种方法都是UIImage
的类方法,使用UIImage
的初始化方法也是可以创建UIImage
对象的大家可以进UIImage
详细了解一下。
0 0
- 五种创建UIImage的类方法
- 五种创建UIImage的类方法
- 五种创建UIImage的类方法
- 五种创建UIImage的类方法
- 5种创建UIImage的类方法
- cocos2dx创建精灵的五种方法
- cocos2dx创建精灵的五种方法
- cocos2dx创建精灵的五种方法
- javascript五种创建对象的方法
- java 五种创建对象的方法
- iOS UIimage拉伸的三种方法
- UIImage的copy方法
- 得到UIImage的方法
- UIImage有关的几个方法
- IOS uiimage 拉伸的方法
- UILable转为UIImage的方法
- UIImage 拉伸特定的方法
- Microstation VBA创建圆弧的五种方法
- httpclient4.2.1最新版连接池配置
- HttpClient4.3教程 第二章 连接管理
- 责任链模式
- 基本文件读写及简单停用词处理
- Elasticsearch集群入门
- 五种创建UIImage的类方法
- nmap#1基本原理
- 数据库事务ACID
- http-关于application/x-www-form-urlencoded等字符编码的解释说明
- es 乐观锁问题重现
- Elasticsearch中的CRUD
- 乐观锁和悲观锁
- C# 文件压缩与解压(ZIP)基于 .Net Framework
- C#数组冒泡排序