ios - 更新 : Image is captured but will not display

标签 ios objective-c uiimagepickercontroller

<分区>

我有一些代码可以在我的一个应用程序上运行;所以我复制了代码,进行了必要的更改(即 textField 名称等)并且它有效,除非我将它移动到 UIImageView;没有出现。这是我的代码:

viewController.h(为简洁起见仅显示相关部分)

#import "AppDelegate.h"
#import "Books.h"
#import <AVFoundation/AVFoundation.h>
#import "MBProgressHUD.h"
#import <MobileCoreServices/MobileCoreServices.h>
#import <UIKit/UIKit.h>

@class Books;

@interface DetailViewController : UIViewController <UITextFieldDelegate,
    UIPopoverControllerDelegate,
    UIPickerViewDataSource,
    UIPickerViewDelegate,
    UIActionSheetDelegate,
    UIScrollViewDelegate,
    UIImagePickerControllerDelegate,
    AVCaptureMetadataOutputObjectsDelegate>  {
}

//  UIView
@property (strong, nonatomic) IBOutlet UIView *bookDetailView;

//  camera stuff
@property (strong, nonatomic) IBOutlet UIImageView *oBookImage;
- (IBAction)bOpenCamera:(UIButton *)sender;

这是相关的 viewController.m 代码:​​

#pragma mark -  Camera stuff
- (IBAction)bOpenCamera:(UIButton *)sender {

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])  {

    UIImagePickerController *imagePicker = [UIImagePickerController new];
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.mediaTypes = [NSArray arrayWithObjects: (NSString *) kUTTypeImage, nil];
    imagePicker.allowsEditing = YES;  //  MUST HAVE!

    [imagePicker setDelegate: (id)self];
    [self presentViewController:imagePicker animated:YES completion:nil];
}

}

-(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo  {

if (error) {
    CommonMethods *cm = [CommonMethods new];
    [cm displayAlert:@"Warning!" andData:@"Failed to save book image..." andTag:0 andViewController:self];
}
}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info  {

self.oBookImage.contentMode = UIViewContentModeScaleAspectFill;

NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:NO completion:nil];

if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {  //  (abstract image data)

    UIImage *image =  [info objectForKey:UIImagePickerControllerOriginalImage];

    //  resize it...
    CGRect screenRect = CGRectMake(0, 0, 114.0, 128.0);  //  was 90.0, 120.0
    UIGraphicsBeginImageContext(screenRect.size);
    [image drawInRect:screenRect blendMode:kCGBlendModePlusDarker alpha:1];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    oBookImage.image = newImage;  //  show it...

}
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker  {

[self dismissViewControllerAnimated:NO completion:nil];
}

更新:在捕获图像时的某个时刻,我收到此警告:

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

也许与此有关?我试图纠正警告,但无济于事。

我在 Google 和 SO 中寻找过类似的问题,但一无所获。我已经为此工作了两天,决定是时候寻求帮助了。提前致谢。

标准差

最佳答案

我也遇到了这个问题。经过几个小时的研究,我发现了这个:iOS8 Snapshotting a view that has not been rendered results in an empty snapshot

也许最后的答案对您有帮助?但愿如此。如果不是,那么它可能只是一个错误。

关于ios - 更新 : Image is captured but will not display,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37228719/

相关文章:

ios - 在比较期间每次都不会调用重写的 isEqual 方法

swift - 从 UIImage 获取 URL 路径 - Framework ImagePicker

ios - 从 ios 中的 UIImageWriteToSavedPhotosAlbum 获取图像名称

ios - UIImagePickerController 在其委托(delegate)不是 View Controller 时崩溃

ios - 在编辑模式下使用自定义滑动操作时如何防止单元格缩进?

ios - 让测试应用程序配置文件不会过期

objective-c - 如何支持更高的 iPhone 5 屏幕尺寸?

iphone - UITableView 分隔符问题

iOS:绘图应用程序 - 绘制圆圈,但新圆圈取代旧圆圈 - 保存状态?