后台处理图片选择器

来源:互联网 发布:巨灵财经数据库 编辑:程序博客网 时间:2024/05/22 06:47
if (self.picker == nil) {                // 1) 显示状态        [SVProgressHUD showWithStatus:@"Loading picker..."];                // 2) 从系统中获取一个并行队列        dispatch_queue_t concurrentQueue =        dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);                // 3) 在后台线程创造图像选择器        dispatch_async(concurrentQueue, ^{                        self.picker = [[UIImagePickerController alloc] init];            self.picker.delegate = self;            self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;            self.picker.allowsEditing = NO;                        // 4) 在主线程中显示那个图像选择器            dispatch_async(dispatch_get_main_queue(), ^{                [self.navigationController presentModalViewController:_picker animated:YES];                [SVProgressHUD dismiss];            });                    });            }  else {        [self.navigationController presentModalViewController:_picker animated:YES];    }
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {         [self dismissModalViewControllerAnimated:YES];     UIImage *fullImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];      // 1) 显示状态    [SVProgressHUD showWithStatus:@"Resizing image..."];     // 2) 从系统获取一个并行队列    dispatch_queue_t concurrentQueue =    dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);     // 3) 在后台完成修改图片大小的运算    dispatch_async(concurrentQueue, ^{         UIImage *thumbImage = [fullImage imageByScalingAndCroppingForSize:CGSizeMake(44, 44)];         // 4) 在主线程显示图片        dispatch_async(dispatch_get_main_queue(), ^{            self.detailItem.fullImage = fullImage;            self.detailItem.thumbImage = thumbImage;            self.imageView.image = fullImage;            [SVProgressHUD dismiss];        });     }); }


原创粉丝点击