【问题标题】:Captured image is not getting saved in the device捕获的图像未保存在设备中
【发布时间】:2016-10-17 03:13:11
【问题描述】:

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

  1. 使用相机捕捉图像:UIImagePickerControllerSourceTypeCamera
  2. UIImagePickerControllerSourceTypeSavedPhotosAlbum加载图片。

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

我的代码是:

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

}

【问题讨论】:

  • 您想将图像存储到您的手机相册中吗? @Purushothaman

标签: ios objective-c iphone uiimagepickercontroller uiactionsheet


【解决方案1】:

只需将此行放入 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ 存储图像

当您捕获图像时,您必须手动存储它。

UIImageWriteToSavedPhotosAlbum(orginalImage,nil, nil, nil);

希望对你有帮助

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      您必须像这样在 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];
                                  }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多