开发者社区 问答 正文

怎样从沙盒里读取图片

已把图片保存,读取的时候也有路径,为什么读不到图片?
//存图片
NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
//获取沙盒路径
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPath atomically:NO];

//读取图片
NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Docments"] stringByAppendingPathComponent:@"currentImage.png"];
UIImage *savedImage = [[UIImage alloc] initWithContentsOfFile:fullPath];

结果savedImage是空的。

展开
收起
a123456678 2016-07-28 10:34:57 2023 分享 版权
1 条回答
写回答
取消 提交回答
  • 兄弟 你少写了个u;
    NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Docments"] stringByAppendingPathComponent:@"currentImage.png"];
    是documents 不是docments

    2019-07-17 20:01:09
    赞同 展开评论
问答地址: