这里用的是CIImage,同样可以转换成UIImage。内容比较简单,适合初学者。(自己忘记时看看,严禁商业转载)
//第一种,从应用程序包中(资源文件)加载图像
NSString * path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"png"];
NSURL * pathURL = [NSURL URLWithString:path];
CIImage * img = [CIImage imageWithContentsOfURL:pathURL];
// NSData * data = [[NSData alloc] initWithContentsOfFile:path];
// CIImage * img = [CIImage imageWithData:data];
// CIImage * img = [[CIImage alloc] initWithData:data];
//第二种,从应用程序沙箱目录中的Document目录下获取图片
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * pathString = [[paths lastObject] stringByAppendingPathComponent:@"1.png"];
NSURL * url = [NSURL URLWithString:pathString];
CIImage * image = [CIImage imageWithContentsOfURL:url];
//也可以转换成NSDate获取
//第三种,从服务器端获取
NSURL * uro = [NSURL URLWithString:@"http://*****/1.png"];
//如果导入了SDWebImage框架,则可以直接根据url地址加载
//没有第三方框架的情况下
NSData * data = [NSData dataWithContentsOfURL:uro];
CIImage * imag = [[CIImage alloc] initWithData:data];
原文地址:http://blog.csdn.net/u010670117/article/details/42963635