我有一个应用程序,用户使用相机拍照,然后选择使用照片。调用以下方法:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
在此方法中,我检查图像的NSData
长度,如果数据 (Kb) 大小太大,则调整实际图像的大小,然后再次检查。这样,我只缩小少量以保持最高质量/尺寸的图像,而不是特定尺寸的 w/h。
问题 我试图在“图像缩放”发生时向用户显示 HUD。HUD 目前没有显示,这是我尝试过的。
// Check if the image size is too large
if ((imageData.length/1024) >= 1024) {
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
HUD.dimBackground = YES;
HUD.labelText = NSLocalizedString(@"HUDHomeLoadingTableData", @"Home View Controller - Loading Table Data");
HUD.removeFromSuperViewOnHide = YES;
while ((imageData.length/1024) >= 1024) {
NSLog(@"While start - The imagedata size is currently: %f KB",roundf((imageData.length/1024)));
// While the imageData is too large scale down the image
// Get the current image size
CGSize currentSize = CGSizeMake(image.size.width, image.size.height);
// Resize the image
image = [image resizedImage:CGSizeMake(roundf(((currentSize.width/100)*80)), roundf(((currentSize.height/100)*80))) interpolationQuality:kMESImageQuality];
// Pass the NSData out again
imageData = UIImageJPEGRepresentation(image, kMESImageQuality);
}
[HUD hide:YES];
}
我正在将 HUD 添加到 self.view 但它没有显示?如果图像缩放在后台线程上完成并且HUD在主线程上更新,我是否也可以考虑这里的线程。我不确定何时确定某些部件是否应该在不同的线程上?