Purushothaman
Purushothaman

Reputation: 358

Captured image is not getting saved in the device

I have created two options in the screen.

  1. To capture the image from camera using : UIImagePickerControllerSourceTypeCamera
  2. To load the image from the UIImagePickerControllerSourceTypeSavedPhotosAlbum.

But when i am capturing the image, image is not storing in the device?

My code is:

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

}

Upvotes: 0

Views: 213

Answers (3)

balkaran singh
balkaran singh

Reputation: 2786

You have to save image camera roll in didFinishPickingMediaWithInfo like this

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage   *image =  [info objectForKey:UIImagePickerControllerOriginalImage];
if(picker.sourceType==UIImagePickerControllerSourceTypeCamera)
                            {

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

Upvotes: 1

Jitendra Modi
Jitendra Modi

Reputation: 2394

Just put this line in - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ to store image

When you capture image you have to store it manually.

UIImageWriteToSavedPhotosAlbum(orginalImage,nil, nil, nil);

Hope this will help you

Upvotes: 1

Julian F. Weinert
Julian F. Weinert

Reputation: 7570

It's because you're not doing anything with the image. You assign it as b64 string to an array and that's it. You must save it to the camera roll manually:

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

Upvotes: 1

Related Questions