程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> camera-在手機相冊中保存圖片失敗

camera-在手機相冊中保存圖片失敗

編輯:編程綜合問答
在手機相冊中保存圖片失敗

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

最佳回答:


這樣設置:

首先設置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];
    }
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved