保存一个可变的图像数组并加载它们 [英] Saving an Mutable array of images and loading them

查看:43
本文介绍了保存一个可变的图像数组并加载它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一部分会拍照,然后该人可以选择保存它,然后将图像保存到阵列中,但是如果不将其放在照片库中,我可以通过什么方法将其保存到手机中.我尝试过

I have part of my app that will take a photo and the person can elect to save it i then save the image to an array but what ways can I save it to the phone WITHOUT it being put in the photo library. I tried

UIImage *image = imageView1.image;

[array addObject: image];

NSUserDefaults *default = [NSUserDefault standardDefaults];
[defaults setObject:image withKey:@"saved image"]; //not exact code just showing the method 

我用来保存图像数组

[defaults synchronize];

然后我还使用 UserDefaults 加载数组,但是它不起作用.我想知道是否存在另一种方法来保存图像而不将其保存到照片库中.

then i also use UserDefaults to load array but it does not work. I am wondering if there is a different way to save images without saving them to the photo library.

推荐答案

原则上,您可以使用

[[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(image) 
                                          forKey:key];

但是请记住, NSUserDefaults 用于存储首选项,而不是图像.最好将图像保存在documents文件夹中,并将路径存储在 NSUserDefaults 中(由Wain建议).

But keep in mind that NSUserDefaults is meant for storage of preferences, not images. You better save the images in the documents folder and store the path in NSUserDefaults (as suggested by Wain).

这篇关于保存一个可变的图像数组并加载它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆