0
我正在創建一個學生索引應用程序,您可以在其中保存學生的姓名,照片和角色。一切正常,但是當我在應用程序測試時創建了一定數量的學生(附圖片)時,該應用程序運行非常緩慢。請找到所附的相應方法。有什麼辦法可以壓縮圖像數據的大小嗎?在保存到核心數據之前壓縮圖像數據
- (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];
}
非常感謝您的回覆。不幸的是,我無法對你的評論贊不絕口,我需要一個更高的評價才能被允許。 –