문제

I am creating a student index app, in which you can save names, pictures and roles of students. Everything works just fine, but when I created a certain amount of students (with pictures) while app-testing, the app runs extremely slow. Please find the corresponding methods enclosed. Is there any way to compress the size of the Image Data?

- (IBAction)cameraButtonPressed:(id)sender
{
    if (! [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] ) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"no access to camera" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
        return;
    }
    UIImagePickerController *controller = [[UIImagePickerController alloc] init];
    controller.delegate = self;
    controller.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:controller animated:YES completion:nil];
}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    [picker dismissViewControllerAnimated:YES completion:nil];    

    _imageView.image = image;
    _imageView.contentMode = UIViewContentModeScaleAspectFit;
}

- (IBAction)save:(id)sender
{
        Student *student = [NSEntityDescription insertNewObjectForEntityForName:@"Student"
                                                             inManagedObjectContext:self.managedObjectContext];

    self.student.picdata = UIImagePNGRepresentation(_imageView.image);

    [self.managedObjectContext save:nil];
    [self.delegate DetailStudentSavePressed:self];
}
도움이 되었습니까?

해결책

You're already compressing the image. When you call UIImagePNGRepresentation, you get a PNG-style compressed image file.

You didn't post the details of your data model, but at a minimum, make sure that the picdata attribute is configured to use external storage in the model editor. Do that first.

If that doesn't help, there are other approaches to reducing the impact of binary blobs on Core Data. But those are not the next step. You specifically mention slowness rather than memory problems, and problems with Core Data and images are far more likely to cause memory issues. Rather than worry about image handling when you have a speed problem, use Instruments to profile your app. You'll find out exactly where it's slowing down.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top