0
A
回答
1
创建文件夹
NSString *pngPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"/WB/%@",self.viewIndex]];
// Check if the directory already exists
BOOL isDir;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:pngPath isDirectory:&isDir];
if (exists)
{
if (!isDir)
{
NSError *error = nil;
[[NSFileManager defaultManager] removeItemAtPath:pngPath error:&error];
// Directory does not exist so create it
[[NSFileManager defaultManager] createDirectoryAtPath:pngPath withIntermediateDirectories:YES attributes:nil error:nil];
}
}
else
{
// Directory does not exist so create it
[[NSFileManager defaultManager] createDirectoryAtPath:pngPath withIntermediateDirectories:YES attributes:nil error:nil];
}
将图像添加到该文件夹
NSString *pngImagePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:[NSString stringWithFormat:@"/WB/%@/%d.png",self.viewIndex,lineIndex]];
UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
self.curImage = UIGraphicsGetImageFromCurrentImageContext();
[UIImagePNGRepresentation(self.curImage) writeToFile:pngImagePath atomically:YES];
UIGraphicsEndImageContext();
+0
@“/ WB /%@”是文件夹名称? – arshad 2014-01-09 08:57:09
+0
WB是文件夹名称,里面的所有图像将在那里。 @arshad – 2014-01-09 08:58:32
0
试试这个:
//为了节省攻略目录
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];
NSDateFormatter *timeFormat = [[NSDateFormatter alloc] init];
[timeFormat setDateFormat:@"HH:mm:ss"];
NSDate *now = [[NSDate alloc] init];
NSString *theDate = [dateFormat stringFromDate:now];
NSString *theTime = [timeFormat stringFromDate:now];
NSString *strImageName=[NSString stringWithFormat:@"Documents/MyPhotos/Dt%@%@.png",theDate,theTime];
strImageName=[strImageName stringByReplacingOccurrencesOfString:@"-" withString:@""];
strImageName=[strImageName stringByReplacingOccurrencesOfString:@":" withString:@""];
[self createDocumentDirectory:@"MyPhotos"];
NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:strImageName];
[UIImagePNGRepresentation(YourImageView.image) writeToFile:pngPath atomically:YES];
-(void)createDocumentDirectory:(NSString*)pStrDirectoryName
{
NSString *dataPath = [self getDocumentDirectoryPath:pStrDirectoryName];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:NULL];
}
-(NSString*)getDocumentDirectoryPath:(NSString*)pStrPathName
{
NSString *strPath = @"";
if(pStrPathName)
strPath = [[kAppDirectoryPath objectAtIndex:0] stringByAppendingPathComponent:pStrPathName];
return strPath;
}
//Get Photo Onebyone
NSError *error = nil;
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self getDocumentDirectoryPath:@"MyPhotos"] error:&error];
if (!error) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self ENDSWITH '.png'"];
NSArray *imagesOnly = [dirContents filteredArrayUsingPredicate:predicate];
for (int i=0;i<[imagesOnly count]; i++) {
[arrSaveImage addObject:[imagesOnly objectAtIndex:i]];//Save in your array.
}
}
相关问题
- 1. 创建文件夹并在其中添加文件
- 2. 添加一个文件夹与图像蚂蚁建立
- 3. 如何在内部存储器中创建文件夹,并在文件夹内添加更多位图?
- 4. 试图创建$ now文件夹并复制.sql文件创建的文件夹
- 5. 崩溃创建图像文件夹
- 6. Php图像创建并上传到文件夹
- 7. 使用Excel VBA创建文件夹并从weblink上传图像?
- 8. 如何在子文件夹中创建多个文件夹.......!
- 9. 创建文件并添加数据? C++
- 10. 创建Word文档并从.NET应用程序添加图像
- 11. Vbscript - 创建一个镜像多组文件夹的脚本
- 12. 蟒蛇 - 创建具有多种颜色的图像,并添加文字
- 13. 从文件创建文件夹,将初始文件复制到文件夹并添加前缀
- 14. 如何创建多个图像文件的zip文件
- 15. 如何在可绘制文件夹内创建一个新文件夹并从中引用图像?
- 16. DotNetZip在不创建文件夹的情况下添加文件
- 17. QT创建者:为.cpp&.h文件添加文件夹
- 18. 无法将图像文件添加到xcode资源文件夹
- 19. 如何在iphone中添加多个图像并删除添加图像?
- 20. 如何添加一个txt文件,并创建一个PHP ZIP
- 21. Python - 通过阅读csv文件创建多个文件夹,并检查文件夹是否已经存在,如果没有创建一个新文件夹
- 22. PHP创建图像,并添加背景图片把它
- 23. 从图像创建自己的地图并添加管脚
- 24. 批量创建子文件夹并将父图像文件复制到新的子文件夹
- 25. .Net core在静态文件夹(www)中添加文件夹并保存图像文件
- 26. 循环创建多个画布,多个图像并不总是显示图像
- 27. 使用批处理文件创建文件夹和多个子文件夹
- 28. PHP动态创建文件夹中的千张图像后的新文件夹
- 29. JsTree删除并创建文件夹?
- 30. Server.MapPath检查文件夹并创建
我想要做同样的事情,你能做到这一点吗?你是怎么做到的?我能够创建目录并在该文件内部,但无法一次获取文件夹的全部内容。我正在获取文件列表,但想要获取整个内容并在一次调用中发送到服务器。请提示。 – reetu 2017-04-06 03:22:56