KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to get something akin to a color mask using exclusively CIImage filters. Basically, I'm looking to make all black pixels transparent. I don't mind what color all the non-black pixels end up having, so long as they have maximum alpha. The code I'm familiar with in Core Graphics to achieve this would look like: // Convert black sections to transparent using a color mask const CGFloat maskingColors[6] = { 0, 0, 0, 0, 0, 0 }; CGImageRef result = CGImageCreateWithMaskingColors(image, maskingColors); I've given it a shot in Core Image using a color matrix filter but it just sets result to nil since the CIVector values are greater than 1.0f . // Create color matrix filter CIFilter *matrix = [CIFilter filterWithName:@"CIColorMatrix"]; // Set filter properties [matrix setValue:image forKey:kCIInputImageKey]; [matrix setValue:[CIVector vectorWithX:1.0f Y:0.0f Z:0.0f W:0.0f] forKey:@"inputRVector"]; [matrix setValue:[CIVector vectorWithX:0.0f Y:1.0f Z:0.0f W:0.0f] forKey:@"inputGVector"]; [matrix setValue:[CIVector vectorWithX:0.0f Y:0.0f Z:1.0f W:0.0f] forKey:@"inputBVector"]; [matrix setValue:[CIVector vectorWithX:255.0f Y:255.0f Z:255.0f W:0.0f] forKey:@"inputAVector"]; // Get the mapped image CIImage *result = [matrix valueForKey:kCIOutputImageKey]; Note: For what it's worth, this is an OSX app.
Tags (comma-separated)
Save Edits
Cancel