我想将UIImage存储在NSMutableDictionary中。
NSData *imgData = UIImagePNGRepresentation(picture.image);
[studDict setValue:imgData forKey:@"Photo"];
其中, studDict 是NSMutableDictionary。 和图片是UIImageView。
并将此dictionnary add作为对象存储在NSMutableArray中。
[studArrayPlist addObject:detailDict];
其中, studArrayPlist 是NSMutableArray。 detailDict 是带有UIImage的NSMutableDictionary。
并且这个NSMutableArray用plist写。
[studArrayPlist writeToFile:plistPath atomically: TRUE];
其中, studArrayPlist 是NSMutableArray存储带有UIImage的NSMutableDictionary。
这不能用plist写。 并且不要给出任何错误。 我还想从plist中检索数组中的所有数据。
答案 0 :(得分:3)
检查对象是否已添加到词典& array.If然后不分配NSMutableArray&的NSMutableDictionary。
NSMutableDictionary *studDict=[[NSMutableDictionary alloc] init];
[studDict setValue:imgData forKey:@"Photo"];
NSMutableArray * studArrayPlist =[[NSMutableArray alloc] init];
[studArrayPlist addObject:studDict];
[studArrayPlist writeToFile: plistPath atomically:YES];
答案 1 :(得分:0)
是的我正在这样做,它运作正常但有时候工作缓慢。
现在, 用于将图像存储为数据
NSMutableDictionary *studDict=[[NSMutableDictionary alloc] init];
NSData *imgData = UIImagePNGRepresentation(picture.image);
[studDict setValue:imgData forKey:@"Photo"];
NSMutableArray * studArrayPlist =[[NSMutableArray alloc] init];
[studArrayPlist addObject:studDict];
[studArrayPlist writeToFile: plistPath atomically:YES];
用于将图像作为数据检索,
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"StudDetail.plist"];
//Storing all the records (NSDictionary objects) in array from plist.
studeInfo = [[NSMutableArray alloc]initWithContentsOfFile:plistPath];
UIImage *img = [[UIImage alloc] initWithData:[[studeInfo objectAtIndex:"your index"] objectForKey:@"Photo"]];
[person setImage:img];
[img release];