【问题标题】:Save image captured by Camera into Documents Directory in ios [duplicate]将相机捕获的图像保存到ios中的文档目录中[重复]
【发布时间】:2013-02-25 09:18:24
【问题描述】:

您好,我是 iPhone 环境的新手。我正在使用 Xcode 4.5。我现在正在开发相机应用程序。我想将从相机拍摄的图像保存到文档目录中的单独文件夹以及照片库中的自定义相册中。我正在将图像保存到照片库中的自定义相册中,但我不知道如何保存它到文档目录...谁能告诉我怎么做...?

【问题讨论】:

    标签: objective-c ios6


    【解决方案1】:

    试试

    UIImage *image = [UIImage imageNamed:@"Image.jpg"];
    NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"New Folder"];
    // New Folder is your folder name
    NSError *error = nil;
    if (![[NSFileManager defaultManager] fileExistsAtPath:stringPath])
        [[NSFileManager defaultManager] createDirectoryAtPath:stringPath withIntermediateDirectories:NO attributes:nil error:&error];
    
    NSString *fileName = [stringPath stringByAppendingFormat:@"/image.jpg"];
    NSData *data = UIImageJPEGRepresentation(image, 1.0);
    [data writeToFile:fileName atomically:YES];
    

    【讨论】:

    • 感谢您的回复..我尝试了此代码,但我必须在哪里查看该图像才能检查图像大小..?
    • 尝试以下路径:Finder -> Go -> Go to Folder -> /Users/GirishS/Library/Application Support/iPhone Simulator。将 GirishS 替换为您的系统名称。
    • 在应用程序支持中没有显示 iPhone 模拟器..!
    • - 在终端上执行以下命令以取消隐藏隐藏文件夹。 chflags nohidden ~/library/
    • iPhone模拟器在执行上述命令后没有显示..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-05
    • 2013-07-29
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多