我想用相机拍照并保存在文档目录中,名称和图像在 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/