【发布时间】:2011-06-30 08:29:14
【问题描述】:
可能重复:
how to store thumbnail image to sqlite table using core data in iphone?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
// Check if it's a photo or video and create MediaItem accordingly
if([[info valueForKey:@"UIImagePickerControllerMediaType"] isEqualToString:(NSString *)kUTTypeImage]){
NSLog(@"Image");
PhotoItem *photo = [NSEntityDescription insertNewObjectForEntityForName:@"PhotoItem" inManagedObjectContext:context];
[photo setImage:[info valueForKey:@"UIImagePickerControllerOriginalImage"]];
currentItem = [photo retain];
// listcell=[NSEntityDescription insertNewObjectForEntityForName:@"BucketListItem" inManagedObjectContext:context];
// [listcell setItemText:@"Photo"];
nameAlert = [[UIAlertView alloc] initWithTitle:@"Enter Photo Name" message:@" " delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
/*CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 150);
[nameAlert setTransform:transform];*/
nameField = [[UITextField alloc] initWithFrame:CGRectMake(20, 50, 245, 20)];
nameField.backgroundColor = [UIColor whiteColor];
nameField.autocapitalizationType = UITextAutocapitalizationTypeWords;
nameField.delegate = self;
[nameAlert addSubview:nameField];
[nameAlert show];
[nameAlert release];
}
我正在使用上面的代码来存储照片库中的图像。我需要将缩略图存储到数据库中。如何做到这一点?
【问题讨论】:
-
我这里没有错误。我不知道如何存储图像,所以我用代码询问。
-
如果你想使用Core Data,首先你必须学习Core Data。然后编写一个模型,用一百行样板代码初始化 Core Data,编写一个缩略图类,将图像以二进制形式保存到其中并保存更改。说明太长,无法在此处发布。另一种方法是将文件写入磁盘并将路径保存到 plist。我会使用文件的 md5 作为文件名。
-
我正在根据需要逐步学习核心数据。我将尝试将文件写入磁盘并将该路径保存到 plist 的替代方法。
-
这是你第三次问这个问题:1。 2。 Please don't do that.
标签: objective-c cocoa-touch ios4 core-data