Fel*_*oux 16

是的你可以:

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:1];
UIImage *img = ...;
[dict setObject:img forKey:@"aKeyForYourImage"];

UIImage *imgAgain = [dict objectForKey:@"aKeyForYourImage"];
Run Code Online (Sandbox Code Playgroud)

  • 不知怎的,它不适合我:(有没有需要做的额外步骤? (6认同)

Rya*_*TCB 6

好的,我最近遇到了这个问题,上述解决方案对我来说没有用.因此,如果其他人在这里找到解决同样问题的方法,那么就是这样做的

NSDictionary *imageDictionary = @{
 kImageKey:  UIImageJPEGRepresentation(/*INSERT YOUR UIImage HERE*/,0.1)
                                 };
Run Code Online (Sandbox Code Playgroud)

// 0.1表示压缩质量0.0最低为1.0是最高质量

然后从字典使用中获取图像

[UIImage imageWithData:[imageDictionary objectForKey: kImageKey]];
Run Code Online (Sandbox Code Playgroud)