gpt4 book ai didi

ios - 将图片保存在位于 iphone 文档目录中的文件夹中

转载 作者:行者123 更新时间:2023-11-28 22:29:54 24 4
gpt4 key购买 nike

我想在文档目录中创建文件夹并将图像保存在该文件夹中。我试过了,但是文件夹和图像存储在文档目录中。但是我想将图像存储在文件夹中。我的代码工作正常,但图像没有保存在文件夹中。

NSError *error;
NSString *aDocumentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *dataPath = [aDocumentsDirectory stringByAppendingPathComponent:@"Folder"];
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error];

NSInteger anIndex = 0;

for (UIImage *anImage in _chosenImages)
{

NSString *anImageName = [NSString stringWithFormat:@"%d.png", anIndex++];
NSString *anImagePath = [NSString stringWithFormat:@"%@/%@", aDocumentsDirectory, anImageName];
NSLog(@"the path is=%@",anImagePath);

NSData *anImageData = UIImagePNGRepresentation(anImage);
[anImageData writeToFile:anImagePath atomically:YES];
}

最佳答案

我猜你的“anImagePath”仍然指向文档目录。将其编辑为“dataPath”作为参数,如下所示

NSString *anImagePath = [NSString stringWithFormat:@"%@/%@", dataPath, anImageName];

关于ios - 将图片保存在位于 iphone 文档目录中的文件夹中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17719610/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com