0

我调用 UIImagePicker 控制器。当我单击相机按钮时,仅显示预览和使用按钮,我的图像未保存在相册中。

代码:

-(void)viewDidAppear:(BOOL)animated{

    picker = [[UIImagePickerController alloc] init];


    // Set the image picker source:
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    // Hide the controls:
    picker.showsCameraControls = YES;
    picker.navigationBarHidden = YES;

    // Make camera view full screen:
    picker.wantsFullScreenLayout = YES;

    // Insert the overlay:
    picker.cameraOverlayView = self.view;

      self.view.backgroundColor=[UIColor clearColor];

    // Show the picker:
    [self presentModalViewController:picker animated:YES];
}
4

2 回答 2

0

用这个

第一组UIImagePickerController委托自我`

-(void)viewDidAppear:(BOOL)animated{

    picker = [[UIImagePickerController alloc] init];
picker.delegte = self ;

    // Set the image picker source:
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    // Hide the controls:
    picker.showsCameraControls = YES;
    picker.navigationBarHidden = YES;

    // Make camera view full screen:
    picker.wantsFullScreenLayout = YES;

    // Insert the overlay:
    picker.cameraOverlayView = self.view;

      self.view.backgroundColor=[UIColor clearColor];

    // Show the picker:
    [self presentModalViewController:picker animated:YES];
}


    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
        {
         UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
         UIImageWriteToSavedPhotosAlbum(image,self,  
                                           @selector(image:finishedSavingWithError:contextInfo:),
                                           nil);
        }

    - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
    {
        UIAlertView *alert;


        if (error)
            alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                               message:@"Unable to save image to Photo Album." 
                                              delegate:self cancelButtonTitle:@"Ok" 
                                     otherButtonTitles:nil];
        else 
            alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                               message:@"Image saved to Photo Album." 
                                              delegate:self cancelButtonTitle:@"Ok" 
                                     otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
于 2013-05-10T09:40:23.870 回答
0
 -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info

{
     UIImage *img=[info valueForKey:@"UIImagePickerControllerOriginalImage"];

      //save the merged image to photo album
     UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
于 2013-05-10T09:41:25.117 回答