2014-04-30 30 views
-3

我的UIImage是零,如果我嘗試測試的代碼塊:的UIImage返回nil(xcode5)

- (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的是無):

enter image description here

我希望有人能幫助我。 在此先感謝您的幫助。

我使用的Xcode 5.1.1(iPhone模擬器:iPhone 4英寸; 64位; iOS7.1)

+0

你是怎麼設置'imgView.image'的? – Logan

+0

我在這個IBAction後的方法中設置了imgView.image(imgView.image = [info objectForKey:@「UIImagePickerControllerEditedImage」];) – user3576580

+0

*哪個*圖像爲零? 'inputImage'或'currentFilteredVideoFrame'? – Caleb

回答

1

如果(如你在評論中說的)問題是inputImage爲零,問題在您發佈的代碼的外部。 imgView本身爲零,或者它指向尚未設置其圖像集的UIImageView實例。把上線斷點:

UIImage *inputImage = imgView.image; 

和檢查imgView,以確定哪些這些可能性的問題。

+0

imgView不是零,imgView中的圖像被設置(從圖庫中選擇)。我在我的問題中發佈了一張圖片。也許它有助於解決這個問題? – user3576580

+0

調試器在執行當前行之前停止。您需要跳過調試程序停止的行,以便分配給inputImage。 – Caleb

+0

好吧,現在inputImage不是零,但它仍然崩潰。而你應該知道的是,IBAction是一個應該改變亮度的UISlider。 – user3576580