title: Compress Image data before saving to Core Data
body: <p>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?</p>
  
  <pre><code>- (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];
  }
  </code></pre>