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

回答

0

使用此

先設置UIImagePickerController delegte 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]; 
    } 
+0

在何處使用這條線?裏面的viewDidAppear? – user2354059 2013-05-10 09:41:09

+0

檢查我的更新答案 – 2013-05-10 09:43:52

+0

這是的UIImagePickerController delegte方法 – 2013-05-10 09:44:27

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); 
} 
+0

在哪裏使用這條線? – user2354059 2013-05-10 09:42:51

+0

請參閱我編輯的答案 – Anil 2013-05-10 09:44:20

+0

在此方法中放置斷點並檢查委託是否被調用 – Anil 2013-05-10 09:47:01