surendher
surendher

Reputation: 1378

How to remove the plain background color from an image

I want to clear the plain background color from an image.

For example,

If i have a picture of a person standing in front of green background, i want the green color to be removed from the image.

Is there any code or API/SDK that performs this functionality.

Any help will be highly appreciated.

@John Rogers - I'm getting the below error when i try running your code. Am i doing anything wrong? enter image description here

Upvotes: 0

Views: 148

Answers (2)

John Rogers
John Rogers

Reputation: 2192

UIImage *image = [UIImage imageNamed:@"image.png"];

const CGFloat colorMasking[6] = {minRed, maxRed, minGreen, maxGreen, minBlue, maxBlue};
image = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(image.CGImage, colorMasking)];

Where min begins at 0 and max begins at 0. Each value is the number of components in the color space of the image.

Upvotes: 1

Klenkee
Klenkee

Reputation: 9

You should just use CGFloat instead of float.

const CGFloat colorMasking[6] = {minRed, maxRed, minGreen, maxGreen, minBlue, maxBlue};

Upvotes: 0

Related Questions