在iOS中加载保存的图像

我正在做的是保存从任何来源(相机/库)加载的图像,并将其保存到iOS中的文件系统。 我卡住了我如何使用该保存图像..我使用下面的代码。 它的工作是在文档文件夹中创build一个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"]; 

使用这个方法:

let testImage = UIImage(contentsOfFile: filePath)

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

在Swift中:

 let testImage = UIImage(contentsOfFile: filePath)