我试图通过按下按钮捕获图片,该按钮是自定义相机覆盖的一部分。我将每个捕获的图片保存到照片库中的相册中。然后在触摸另一个按钮时,用户可以查看画廊视图中的所有图片。一切正常,但是当快速连续触摸按钮时,我收到以下错误:
UIImagePickerController:忽略拍照请求;相机是 尚未准备好
这是代码
//Capture image on custom buton click
- (IBAction)captureImage:(id)sender {
[_photoSharingImagePicker takePicture];
//_btnTakePicture.enabled = false;
}
UIImage *editedImage, *originalImage, *imageToSave;
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if(CFStringCompare((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo)
{
editedImage = (UIImage *) [info objectForKey:
UIImagePickerControllerEditedImage];
originalImage = (UIImage *) [info objectForKey:
UIImagePickerControllerOriginalImage];
// Resizing and setting image to goto gallery button
CGSize imageSize = _btnGotoGallery.frame.size;
UIGraphicsBeginImageContext(imageSize);
CGRect imageRect = CGRectMake(0.0, 0.0, imageSize.width, imageSize.height);
[originalImage drawInRect:imageRect];
editedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_btnGotoGallery setBackgroundImage:editedImage forState:UIControlStateNormal];
imageToSave = originalImage;
}
// Save the new image (original or edited) to the Camera Roll
//Need user permission for photos
//UIImageWriteToSavedPhotosAlbum (imageToSave, self, @selector(image:didFinishSavingWithError:contextInfo:) , nil);
//Save image in an album with the app's name
_assetsLibrary = [[ALAssetsLibrary alloc] init];
[_assetsLibrary saveImage:imageToSave toAlbum:@"DTE" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
DLog(@"Big error: %@", [error description]);
}
}];
有时我得到的是黑色图像 我该如何防止这种情况?