7
votes

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?

5

5 Answers

1
votes

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.

0
votes

Try adding this delegate-method to see what the error is:

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

To save try this in your application didFinishLaunchingWithOptions method:

NSString *path = [[NSBundle mainBundle]pathForResource:@"" ofType:@""];
UISaveVideoAtPathToSavedPhotosAlbum(path, self, @selector(video:didFinishSavingWithError:contextInfo), nil);
0
votes

First of all try saving your image clicked from camera somewhere as NSData and then access the image in NSData form, convert it in UIImage and display on the imageView.

For example you can use document directory to create a plist where you can save the image as NSData in method -

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

}

And when saving the image in method you used - -(IBAction)save:(id)sender{ }

you can access the same image from the plist in Document directory.Convert the NSData as UIImage and display it on imageView.I am sure no error will survive then.

This error ": CGAffineTransformInvert: singular matrix." occurs due to the image orientation property of an image.When saving the image as NSData stores the image property.And you get the image with no error.

0
votes

You need to implement something

-(IBAction) pickphoto
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {  
        UIImagePickerController *picker= [[UIImagePickerController alloc]init];
        picker.delegate = self;
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [yourView presentModalViewController:picker animated:YES];
        picker.videoQuality = UIImagePickerControllerQualityTypeHigh;
        picker.allowsEditing = NO;
        [picker release];
    }
}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage : (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissModalViewControllerAnimated:YES];
    myImage.image=image;
}