0
可能重複:
how to store thumbnail image to sqlite table using core data in iphone?如何在iphone中使用核心數據將圖像存儲到sqlite?
- (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];
}
我使用上面的代碼存儲從照片gallery.i圖像需要保存縮略圖database.how這樣做呢?
我在這裏沒有錯誤。我不知道如何存儲圖像,因爲我問代碼。 –
如果你想使用核心數據,首先你必須學習核心數據。然後編寫一個模型,用百行代碼初始化核心數據,編寫一個縮略圖類,將圖像保存爲二進制文件並保存更改。說明會太長,不能在這裏發佈。另一種方法是將文件寫入磁盤並將路徑保存到plist。我會使用文件的md5作爲文件名。 – Jano
我正在逐步學習核心數據,因爲我需要。我會嘗試將文件寫入磁盤並將該路徑保存到plist。 –