iphone - 相机照片保存在文档文件夹中,并在 iPhone 的桌面 View 中显示名称和 View

标签 iphone ios xcode

我想用相机拍照并保存在文档目录中,名称和图像在 UITableViewCell 中可见。

如果我选择任何一行,相应的行图像将转到带有名称和图像的下一个 View 。

请给出您的想法、建议和引用代码。

最佳答案

尝试此方法将 UIImage 存储在本地目录中...

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

 UIImage *pickedImage = [info objectForKey:UIImagePickerControllerEditedImage];
 [self addImage:pickedImage toCacheWithIdentifier:@"NAME OF THE IMAGE"];

}

- (void)addImage:(UIImage *)image toCacheWithIdentifier:(NSString *)identifier {

    NSString *folderPath = @"LOCAL DIRECTORY PATH ";
    if(![[NSFileManager defaultManager] fileExistsAtPath:folderPath isDirectory:nil]) {

        [[NSFileManager defaultManager] createDirectoryAtPath:folderPath withIntermediateDirectories:YES attributes:nil error:nil];
    }

    NSString *fileName = [NSString stringWithFormat:@"%@.png",identifier];

 fileName = [folderPath stringByAppendingPathComponent:fileName];

 NSData *imageData = UIImagePNGRepresentation(image);

   [imageData writeToFile:fileName atomically:YES];
}

要在单击 tableView 单元格时检索图像,请从 didselectRowAtIndexPath 调用此方法 ....

- (UIImage *)imageFromCacheWithIdentifier:(NSString *)identifier {

    NSString *folderPath = @"LOCAL DIRECTORY PATH ";

    NSString *fileName = [NSString stringWithFormat:@"%@.png",identifier];

    fileName = [folderPath stringByAppendingPathComponent:fileName];

    if([UIImage imageWithContentsOfFile:fileName]) {

        return [UIImage imageWithContentsOfFile:fileName];

    }

    return nil;
}

关于iphone - 相机照片保存在文档文件夹中,并在 iPhone 的桌面 View 中显示名称和 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19378947/

相关文章:

iphone - 重新加载数据时 TableView Controller 不显示事件状态

iphone - 绘制 UITableviewcell 时的动画

ios - 为我的 flutter 应用程序运行 IOS 模拟器的问题

ios - Swift 反射 - 如何检查反射值是否是一种类型

iphone - 用于 iOS 的带有 openssl 的 libwebsockets lib 在 SSL_CTX_new() 中崩溃

iphone - 确定 UILocalNotification 是在前台还是后台通过应用程序触发的

Xcode 6 测试版 : I'm not able to select Swift as language

ios - 使用 Xcode iOS 的 TableView 中的选择(或单选)列表?

xcode - 如何将 Box2d 添加到现有的 Xcode/Cocos2d 项目

iphone - 导入错误 <cocoa/cocoa.h>