OGeek|极客世界-中国程序员成长平台

标题: ios - 将 UIImage 保存在应用程序路径中 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 12:51
标题: ios - 将 UIImage 保存在应用程序路径中

(对不起我的英语)

我需要将图像保存在应用程序路径中,然后在 ImageView 上加载图像。

获取应用路径:

NSString * imagePath = NSHomeDirectory(); 
imagePath = [imagePath stringByAppendingPathComponent"/image.png"];

之后,保存图片:

NSData *imageData = UIImagePNGRepresentation(self.imageView.image);
[imageData writeToFile:self.imagePath atomically:YES]

加载保存在应用路径上的图片

self.imageSaved.image = [UIImage imageWithContentsOfFile:self.imagePath];

问题是图像没有保存到路径中

问候

编辑:

问题解决了,只需要修改文件路径

[imagePath stringByAppendingPathComponent"Documents/image.png"];

感谢您的回答。



Best Answer-推荐答案


   NSString *imagePath = NSHomeDirectory();
   imagePath = [imagePath stringByAppendingPathComponent"/Documents/image.png"];

   imagePath = [imagePath stringByAppendingPathComponent"/Library/image.png"];

关于ios - 将 UIImage 保存在应用程序路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9995993/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4