首页 文章

UIImage返回nil(xcode5)

提问于
浏览
-3

如果我尝试测试这段代码,我的UIImage是零:

- (IBAction)sliderBrightness:(id)sender {

    UIImage *inputImage = imgView.image;

    GPUImageBrightnessFilter *stillImageFilter = [[GPUImageBrightnessFilter alloc] init];
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];

    [stillImageSource addTarget:stillImageFilter];
    [stillImageFilter useNextFrameForImageCapture];
    [stillImageSource processImage];

    UIImage *currentFilteredVideoFrame = [stillImageFilter imageFromCurrentFramebuffer];
    [self->imgView setImage:currentFilteredVideoFrame];
}

UPDATE:

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

imgView.image = [info objectForKey:@"UIImagePickerControllerEditedImage"];

if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {

    toolbar.hidden = NO;

    UIImage *image1 = imgView.image;
    NSString *cachedFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *cachedImagePath = [cachedFolderPath stringByAppendingPathComponent:@"image1.png"];
    [UIImagePNGRepresentation(image1) writeToFile:cachedImagePath atomically:YES];

}

if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {

    toolbar.hidden = NO;

    UIImage *image1 = imgView.image;
    NSString *cachedFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *cachedImagePath = [cachedFolderPath stringByAppendingPathComponent:@"image1.png"];
    [UIImagePNGRepresentation(image1) writeToFile:cachedImagePath atomically:YES];
}

if (picker.sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum) {

    toolbar.hidden = NO;

    UIImage *image1 = imgView.image;
    NSString *cachedFolderPath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)[0];
    NSString *cachedImagePath = [cachedFolderPath stringByAppendingPathComponent:@"image1.png"];
    [UIImagePNGRepresentation(image1) writeToFile:cachedImagePath atomically:YES];
}

else{

    toolbar.hidden = NO;

}

[self dismissViewControllerAnimated:YES completion:nil];

}

调试器(inputImage为nil):

enter image description here

我希望有一个人可以帮助我 . 在此先感谢您的帮助 .

我正在使用xcode 5.1.1(iOS模拟器:iPhone 4英寸; 64位; iOS7.1)

1 回答

  • 1

    如果(正如您在评论中所述)问题是 inputImage 为零,则问题是您发布的代码的外部问题 . 要么 imgView 本身为零,要么它指向尚未设置其图像的 UIImageView 实例 . 在线上放一个断点:

    UIImage *inputImage = imgView.image;
    

    并检查 imgView 以确定哪些可能性是问题所在 .

相关问题