我試圖從使用下面的代碼從相冊中挑選後獲取圖像路徑。但它總是將圖像路徑設置爲NULL /崩潰。是什麼原因?有人能幫助我嗎?iPhone:在didFinishPickingImage中沒有獲取圖像路徑URL
-(IBAction) LaunchAlbum :(id) sender
{
// Updated - overlay code.
MyAppDelegate *appDelegate = (MyAppDelegate *)[UIApplication sharedApplication].delegate;
appDelegate.pickerController = [[UIImagePickerController alloc] init];
appDelegate.pickerController.delegate = self;
//appDelegate.pickerController.allowsEditing = NO;
//appDelegate.pickerController.mediaTypes = [NSArray arrayWithObject:@"public.image"];
appDelegate.pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:appDelegate.pickerController animated:YES];
[ appDelegate.pickerController release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
imageUrl = [info valueForKey:@"UIImagePickerControllerReferenceURL"]; // CRASH
selectedImage = [imageUrl path];
NSLog(@"selectedImage: %@", selectedImage);
}
您好,我註釋掉appDelegate.pickerController.allowsEditing = NO;不過靜止圖像路徑爲空。但我確信我通過在imageview中添加圖像來獲得正確的圖像。圖像路徑URL仍爲NULL。 – Getsy
@Getsy,調試你的應用程序!檢查editInfo是否爲零。然後NSLog整個editInfo看看它有什麼。 –
它不是NULL。它是這樣給出的 - > {UIImagePickerControllerCropRect =「NSRect:{{0,0},{147,140}}」; UIImagePickerControllerEditedImage =「」; UIImagePickerControllerMediaType =「public.image」; UIImagePickerControllerOriginalImage =「」; } –
Getsy