【问题标题】:Image not saving in photo Album图像未保存在相册中
【发布时间】:2013-05-10 09:36:08
【问题描述】:

我调用 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];
}

【问题讨论】:

    标签: iphone objective-c camera uiimagepickercontroller screenshot


    【解决方案1】:

    使用这个

    第一组UIImagePickerControllerdelegte self`

    -(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];
        }
    

    【讨论】:

    • 这条线在哪里使用?在 viewDidAppear 里面?
    • 这是 UIImagePickerController 委托方法
    • 没有。它没有保存到相册
    • 可以设置 UIImagePickerController 委托
    • 首先你先设置委托picker.delegte = self
    【解决方案2】:
     -(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
    
    {
         UIImage *img=[info valueForKey:@"UIImagePickerControllerOriginalImage"];
    
          //save the merged image to photo album
         UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
    }
    

    【讨论】:

    • 在这个方法下放断点,检查是否调用了委托
    猜你喜欢
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 2014-08-28
    • 2011-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    相关资源
    最近更新 更多