如何将 UIImage 对象的 NSArray 写入文件?

发布于 2024-11-30 20:37:03 字数 355 浏览 1 评论 0原文

我一直在尝试使用 NSMutableArray 的 writeToFile:atomically:

但有人向我指出这种方法是错误的:即 iPhone / Objective-C:NSMutableArray writeToFile 不会写入文件。总是返回“否”

看来我必须阅读上述链接的答案之一中提到的存档指南。

有人愿意分享(或向我指出)一些可以帮助我完成这项任务的代码吗?

I have been attempting to use NSMutableArray's writeToFile:atomically:

But it has been pointed out to me that this approach is wrong: i.e. iPhone / Objective-C: NSMutableArray writeToFile won't write to file. Always returns NO

It looks like I'm going to have to read the guide on archiving that is referred to in one of the answers in the above link.

Would anyone care to share (or point me towards) some code that helps me accomplish this task?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送君千里 2024-12-07 20:37:03

您提到的方法在写出文件之前递归地验证所有包含的对象都是属性列表对象。

试试这个:

for (UIImage *image in arrayWithImages) {
    NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@", @"nameOfTheImage.png"]];
    UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
}

也许你可以使用 [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPathatomically:YES]; 将图像写入 jpeg。

The method, you've mentioned recursively validates that all the contained objects are property list objects before writing out the file.

Try this:

for (UIImage *image in arrayWithImages) {
    NSString *pngPath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@", @"nameOfTheImage.png"]];
    UIImagePNGRepresentation(image) writeToFile:pngPath atomically:YES];
}

Maybe you can use [UIImageJPEGRepresentation(image, 1.0) writeToFile:jpgPath atomically:YES]; to write image as jpeg.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文