Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems loading and saving images from camera and camera roll. What am I doing wrong?

I am building an app in which you can make pictures or pick an image from the camera roll and save these inside the app to be displayed in a tableview and detailview. The problem is that when I make a picture from inside the app and save it, the tableview and detailview get terribly slow as if the app is freezing. I also get this error ": CGAffineTransformInvert: singular matrix.". When I load a picture from the camera-rol that was not taken from inside my app, there is no problem and the app runs very smouthly.

This is the code for when I open the camera and camera roll:

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex == actionSheet.cancelButtonIndex) {
    return;
}

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = NO;

switch (buttonIndex) {
    case 0:
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        }
        break;
    case 1:
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
            picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        }
        break;
}

[self presentModalViewController:picker animated:YES];  
}

This is where I save it to the camera roll and put the image in an imageView:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
UIImage *mijnImage;
if (CFStringCompare((__bridge_retained CFStringRef)mediaType, kUTTypeImage, 0)==kCFCompareEqualTo) {
    mijnImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
    mijnPlaatje_.image = mijnImage;
    UIImageWriteToSavedPhotosAlbum(mijnImage, nil, nil, nil);

}

 [picker dismissModalViewControllerAnimated:YES]; 

}

And here I save the image inside my app:

-(IBAction)save:(id)sender{
drankjes.plaatje = [mijnPlaatje_ image];
[self dismissModalViewControllerAnimated:YES];

}

What am I doing wrong?

like image 833
Max Uylings Avatar asked Dec 12 '11 11:12

Max Uylings


People also ask

Why is my camera roll not showing up in Picture Library?

This issue could have occurred if the Camera Roll folder is not added to the Picture Library properly. I would suggest you to manually add the Camera Roll folder to Picture Library and check if it helps. a) Right-click on Picture Library. b) Click on Properties. c) Click on Add button.

What to do if your camera roll is missing in Windows 10?

If you get an error message that says your camera roll is missing (0xA00F4275) when you try to take a picture or video with the Camera app in Windows 10, try the following solutions, in the order listed. Select Start > Settings > System > Storage > Change where new content is saved.

Why is my camera roll missing (0xa00f4275)?

If you get an error message that says your camera roll is missing (0xA00F4275) when you try to take a picture or video with the Camera app in Windows 10, try the following solutions, in the order listed. Change where new pictures and videos are saved Select Start  > Settings  > System  > Storage > Change where new content is saved.

How to delete unwanted photos from iPhone camera roll?

You can use TunesGo to delete unwanted photos from your iPhone, and you can post more pictures to the camera roll. Step 1 Start Wondershare TunesGo on your computer and connect your iPhone. Step 2 Backup the photos to the computer by clicking the “ Backup Photos to PC ” on the main interface.


1 Answers

You need to use:

UIImageWriteToSavedPhotosAlbum(image, self, @selector(video:didFinishSavingWithError:contextInfo), nil)

and implement:

- (void)image:(UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo {
    NSLog(@"Saving image");
    if(error != nil) {
        NSLog(@"Error saving: %@",[error localizedDescription]);
    }
}

as Jensen2K says, didFinishSavingWithError is called even if there is no error so you can use it to tell when the save has finished.

like image 153
Russ Avatar answered Oct 19 '22 02:10

Russ