Search code examples
iosgpuimage

Adding the Image in bundle to the UIImageView using GPU Image?


I am very new to the user of GPU Image Framework. In my application I use the following code to get the filter effect of the Image in bundle(knee.png) , But I get only Black ImageView . I get the code from this link

show me where I went wrong  

UIImage *inputImage = [UIImage imageNamed:@"knee.png"];        
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
    GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];    
    [stillImageSource addTarget:stillImageFilter];
    [stillImageSource processImage];  
    UIImage *quickFilteredImage = [stillImageFilter imageByFilteringImage:inputImage];
    [self.imgView setImage:quickFilteredImage];

Solution

  • You're mixing two ways of accomplishing the same thing in your code sample. Try this as the simplest method of filtering the image:

    UIImage *inputImage = [UIImage imageNamed:@"knee.png"];        
    GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];    
    UIImage *quickFilteredImage = [stillImageFilter imageByFilteringImage:inputImage];
    [self.imgView setImage:quickFilteredImage];
    

    Or the longer, more flexible flow, which makes it easier to chain multiple filters:

    UIImage *inputImage = [UIImage imageNamed:@"knee.png"];        
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
    GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];    
    [stillImageSource addTarget:stillImageFilter];
    [stillImageSource processImage];  
    UIImage *quickFilteredImage = [stillImageFilter imageFromCurrentlyProcessedOutput];
    [self.imgView setImage:quickFilteredImage];
    

    It does look like your original code should've produced an image though. To debug I'd check the input image (and add it to your question), display it in another view before filtering, look at GPUImageView for displaying stillImageSource, and as a target for your filter before writing to another UIImage.