Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9203351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:27:15+00:00 2026-06-17T23:27:15+00:00

I would like to apply a linear gradient to a photo using Core Image.

  • 0

I would like to apply a linear gradient to a photo using Core Image. Here is the code that I am using (or you can check it out in an Xcode project: http://cl.ly/2Z0Z2f1a3Q27):

CIContext *coreImageContext = [CIContext contextWithOptions:nil];

CIFilter *gradientFilter = [CIFilter filterWithName:@"CILinearGradient"];
[gradientFilter setDefaults];
CIColor *startColor = [CIColor colorWithCGColor:[UIColor yellowColor].CGColor];
CIColor *endColor = [CIColor colorWithCGColor:[UIColor blackColor].CGColor];
CIVector *startVector = [CIVector vectorWithX:100 Y:0];
CIVector *endVector = [CIVector vectorWithX:100 Y:100];
[gradientFilter setValue:startVector forKey:@"inputPoint0"];
[gradientFilter setValue:endVector forKey:@"inputPoint1"];
[gradientFilter setValue:startColor forKey:@"inputColor0"];
[gradientFilter setValue:endColor forKey:@"inputColor1"];

UIImage *originalImage = [UIImage imageNamed:@"testImage.jpeg"];
CIImage *ciImage = [CIImage imageWithCGImage:originalImage.CGImage];
[gradientFilter setValue:ciImage forKey:kCIInputImageKey];
CIImage *resultCIImage = [gradientFilter valueForKey:kCIOutputImageKey];
CGImageRef resultCGImage = [coreImageContext createCGImage:resultCIImage fromRect:[resultCIImage extent]];
UIImage *resultUIImage = [UIImage imageWithCGImage:resultCGImage scale:[[UIScreen mainScreen] scale] orientation:UIImageOrientationUp];
CGImageRelease(resultCGImage);

UIImageView *filteredImageView = [[UIImageView alloc] initWithImage:resultUIImage];

Running this code on the device (iPhone 5, iOS 6.0.1) and simulator (iOS 6) produces an exception:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CILinearGradient 0x1f857ee0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key inputImage.'

The line that the exception is occurring is [gradientFilter setValue:ciImage forKey:kCIInputImageKey].

Here is a sample Xcode project that you can build to see this error: http://cl.ly/2Z0Z2f1a3Q27

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:27:16+00:00Added an answer on June 17, 2026 at 11:27 pm

    CILinearGradient only has the four properties – two points and two colors. You would have to chain a CILinearGradient with a CISourceOverCompositing filter to composite a gradient over an image. See filter reference:

    https://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CoreImageFilterReference/Reference/reference.html#//apple_ref/doc/filter/ci/CILinearGradient

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So if you have code like this: background: url('image.png'); background: -webkit-gradient(linear, left top, left
I have a loading image that I would like to apply as a splash
I would like to apply FileIOPermission on set of files using mask in file
I would like to apply CSS styles to links that appear in column headers
I am using TortoiseHg and would like to apply a hook to my repo.
I have a dataframe and I would like to apply a function that takes
I have some auto-instantiation code which I would like to apply to about 15
I have a HtmlHelper extension method that I would like to apply some logic
I have a UITableView and would like to apply a background image to all
I have a filter that would like to apply to all controllers except for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.