捕获的图像未保存在设备中

时间:2016-10-17 03:13:12

标签: ios objective-c iphone uiimagepickercontroller uiactionsheet

我在屏幕上创建了两个选项。

  1. 使用以下方法从相机捕获图像:UIImagePickerControllerSourceTypeCamera
  2. UIImagePickerControllerSourceTypeSavedPhotosAlbum
  3. 加载图片

    但是当我拍摄图像时,图像没有存储在设备中?

    我的代码是:

    -(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
    
        NSLog(@"From didDismissWithButtonIndex - Selected Option: %@", [actionSheet buttonTitleAtIndex:buttonIndex]);
    
        NSString*image=[actionSheet buttonTitleAtIndex:buttonIndex];
    
        if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Camera"]) {
    
            if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
            {
                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Device Camera Is Not Working" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
                [alert show];
                return;
            }
            else{
    
                UIImagePickerController *picker = [[UIImagePickerController alloc] init];
                picker.delegate = self;
                picker.allowsEditing = YES;
                picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    
    
    
                [self presentViewController:picker animated:YES completion:NULL];
    
            }
        }
    
        else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Gallery"])
        {
            UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
            pickerView.allowsEditing = YES;
            pickerView.delegate = self;
            [pickerView setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    
            //[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            [self presentViewController:pickerView animated:YES completion:nil];
    
        }
    }
    #pragma mark - PickerDelegates
    
    //=====================================Image picker ===============================================
    
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    
        UIImage* orginalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
    
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:isRowIndex inSection:isSectionIndex] ;
    
        UITableViewCell *cell = [jobstable cellForRowAtIndexPath:indexPath];
    
        UIImageView *tableIMAGE=(UIImageView *)[cell.contentView viewWithTag:19];
    
        tableIMAGE.image=orginalImage;
    
        imageStris = [UIImageJPEGRepresentation(tableIMAGE.image,1)base64Encoding];
    
        answersARRAY[indexPath.row] = [NSString stringWithFormat:@"-1,%@,%@",answersARRAY[indexPath.row],imageStris];
    
        [self visubull];
    
        [self dismissViewControllerAnimated:YES completion:nil];
    
    }
    
    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    
        [picker dismissViewControllerAnimated:YES completion:NULL];
    
    }
    

3 个答案:

答案 0 :(得分:1)

这是因为你没有对图像做任何事情。您将它作为b64字符串分配给一个数组,就是这样。您必须手动将其保存到相机胶卷:

UIImageWriteToSavedPhotosAlbum(tableIMAGE.image, nil, nil, nil);

答案 1 :(得分:1)

只需将此行放入 UIImageWriteToSavedPhotosAlbum(orginalImage,nil, nil, nil); 即可存储图片

捕捉图像时,必须手动存储。

{{1}}

希望这会对你有所帮助

答案 2 :(得分:1)

你必须像这样

在didFinishPickingMediaWithInfo中保存图像相机胶卷
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage   *image =  [info objectForKey:UIImagePickerControllerOriginalImage];
if(picker.sourceType==UIImagePickerControllerSourceTypeCamera)
                            {

                                [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
                                    [PHAssetChangeRequest creationRequestForAssetFromImage:image];
                                } completionHandler:nil];
                            }
}