我在屏幕上创建了两个选项。
UIImagePickerControllerSourceTypeCamera
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];
}
答案 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];
}
}