0

我使用创建了多个目录

NSArray *directoryNames = [NSArray arrayWithObjects:@"t",@"b",@"p",@"c", @"S", @"h", @"o",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder

for (int i = 0; i < [directoryNames count] ; i++) {
    NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:[directoryNames objectAtIndex:i]];
    if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
        [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:nil]; 

但是,我想对 UIImage 上显示的照片进行排序,然后对用户使用 pickerview 选择的照片进行排序。我想知道要保存到我制作的这些特定目录中的代码。任何帮助是极大的赞赏!

更新我知道

在应用程序的任何位置使用您创建的目录。

NSArray *directoryNames = [NSArray arrayWithObjects:@"tops",@"bottoms",@"right",@"left",nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder

// This will return the folder name in the 0 position. In yours "tops"
NSString *topDirPath = [documentsDirectory stringByAppendingPathComponent:[directoryNames objectAtIndex:0]];
// This will return the file path in your "tops" folder
NSString *filePath = [topDirPath stringByAppendingPathComponent:@"MYIMAGE"];

存储图像文件

NSData *imageDataToStore = UIImagePNGRepresentation(image);
[imageDataToStore writeToFile:filePath atomically:YES];

我不知道在哪里声明我的目录名

4

1 回答 1

1

要将图像保存到文件夹中的文件,您需要获取图像的数据 ( UIImageJPEGRepresentation),然后将该数据保存到磁盘 ( writeToFile:atomically:)。

于 2013-08-11T17:16:35.890 回答