我在下面发布的代码有两个功能;第一个是拍一张照片(工作正常),第二个是从图书馆(这是不工作)的图像。这些函数没有正确调用。请检查我的代码,并让我知道最新的错误。从我的书架中添加照片时出错?
在此先感谢。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
static NSDateFormatter *dateFormatter = nil;
NSString *stringDate = nil;
if (dateFormatter == nil) {
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EE, d LLLL yyyy"];
stringDate = [dateFormatter stringFromDate:[NSDate date]];
}
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// storing to camera roll
UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:finishedSavingWithError:contextInfo:),nil);
CGSize newSize=CGSizeMake(320, 436);
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
xapp.profileImage=newImage;
[[NSNotificationCenter defaultCenter]postNotificationName:@"addImage" object:nil];
}
// Commit the change.
[self dismissModalViewControllerAnimated:YES];
}
-(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Save failed"
message: @"Failed to save image"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
以什么方式是从库代码挑选不工作?它会产生错误吗?拾取器是否出现? – gaige 2013-03-18 12:38:14
第二个函数在UIImagePickerController运行时发生错误时调用,而不是从库中加载照片时调用。你能对这个错误有更详细的了解吗?你是如何调用UIImagePickerController从库中加载的? – 2013-03-18 12:39:12
图书馆是开放的罚款如果选择一个图像,图像不显示在imageView – 2013-03-18 12:46:54