在iOS中加载已保存的图像

时间:2011-11-26 09:59:43

标签: ios filesystems

我正在做的是保存从任何来源(相机/库)加载的图像并将其保存到iOS中的文件系统。 我被困在的是如何使用该保存图像.. 我使用以下代码。它的工作是在Documents Folder中创建一个Test.jpg。 但真的不知道如何访问这个Test.jpg。

NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Test.jpg"];
[UIImageJPEGRepresentation(selectedImage.image, 1.0) writeToFile:jpgPath atomically:YES];
NSError *error;
NSFileManager *fileMgr = [NSFileManager defaultManager];  
NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

2 个答案:

答案 0 :(得分:16)

使用此方法:

let testImage = UIImage(contentsOfFile: filePath)

imageNamed在应用程序的主程序包中查找具有指定名称的图像。

答案 1 :(得分:3)

在斯威夫特:

let testImage = UIImage(contentsOfFile: filePath)