我想将相机中已保存的图像或已保存的图像保存到iPhone中的照片库 在这里我实现了一些代码,但是我无法在按钮点击上实现它,而且它正在崩溃。
我对iPhone编程方面很陌生。有谁知道我做错了什么?
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info:(id)sender{
UIImage *selectedImage;
NSURL *mediaUrl;
mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
if (mediaUrl == nil)
{
selectedImage = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage];
if (selectedImage == nil)
{
selectedImage = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
NSLog(@"Original image picked.");
}
else
{
NSLog(@"Edited image picked.");
}
}
else
{
NSLog(@"Video picked. Not yet implemented.");
}
[picker dismissModalViewControllerAnimated:YES];
imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
if((UIButton *) sender == savePhotoBtn) {
UIImageWriteToSavedPhotosAlbum(selectedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
}
}
答案 0 :(得分:0)
我的功能正在执行...我用printf语句检查..
/* Globaly declared */
NSDictionary *info1;
UIImagePickerController * picker;
-(IBAction) savePhoto:(id) sender
{
UIImage *selectedImage;
NSURL *mediaUrl;
mediaUrl = (NSURL *)[info1 valueForKey:UIImagePickerControllerMediaURL];
if (mediaUrl == nil)
{
selectedImage = (UIImage *) [info1 valueForKey:UIImagePickerControllerEditedImage];
if (selectedImage == nil)
{
selectedImage = (UIImage *) [info1 valueForKey:UIImagePickerControllerOriginalImage];
NSLog(@"Original image picked.");
}
else
{
NSLog(@"Edited image picked.");
}
}
else
{
NSLog(@"Video picked. Not yet implemented.");
}
picker.allowsImageEditing = YES;
//if((UIButton *) sender == savePhotoBtn) {
UIImageWriteToSavedPhotosAlbum(selectedImage, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
//}
printf(" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ");
}