gpt4 book ai didi

objective-c - 如何使用 NSFileManager 将 UIImage 保存到文件?

转载 作者:太空狗 更新时间:2023-10-30 03:13:18 34 4
gpt4 key购买 nike

如何使用 NSFileManager 将 UIImage 保存到文件?

谢谢

最佳答案

我们开始吧。

这会将 UIImage 存储到您的 iOS 应用程序的文档目录中。你不需要 NSFileManager

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

UIImage * imageToSave = [UIImage imageNamed:@"Icon.png"];
NSData * binaryImageData = UIImagePNGRepresentation(imageToSave);

[binaryImageData writeToFile:[basePath stringByAppendingPathComponent:@"myfile.png"] atomically:YES];

编辑:如果您存储来自 iOS 相机的图像,您可能会了解如何将图像旋转到正确的方向。 Look here in that case .

关于objective-c - 如何使用 NSFileManager 将 UIImage 保存到文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10094195/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com