How do you set the inputTransform for CIAffineTransform in iOS 5
Asked Answered
W

2

10

I've been looking around for a while for an answer to this, but haven't found anything. I'm trying to use the CIAffineTransform thats apart of iOS 5 Beta, and have come across an issue. The documentation says that the 'inputTransform' property accepts an NSAffineTransform, but near as I can tell, there is no way to instantiate one of these in iOS, all the research I've done tells me this particular class is for MacOS (correct me if I'm wrong).

If thats the case, then what value do I put into the inputTransform?

Here's some simple code to explain what I'm trying to accomplish.

CIImage* result = "Some CIImage";


CIFilter* filter = [CIFilter filterWithName:@"CIAffineTransform"];
[filter setValue:result forKey:kCIInputImageKey];

[filter setValue:transform forKey:@"inputTransform"]; //What type/class of value do I set here if I can't use an NSAffineTransform

result = [filter outputImage];

Any help will be greatly apprecriated.

Wreckage answered 10/8, 2011 at 12:27 Comment(0)
W
24

I found the solution, I was simply looking in the wrong place.

Instead of using the CIAffineTransform filter on the CIImage, CIImage actually provides a method called:

-(CIImage*) imageByApplyingTransform:(CGAffineTransform)transform

This method returns an image that has the CGAffineTransform argument applied to it.

Hope that helps somebody :)

Wreckage answered 10/8, 2011 at 20:46 Comment(2)
Thanks, this is still helpful 2 years later! I'm just curious why my filter spits nil when I use CIAffineTransform, either with [NSValue valueWithBytes:&xform objCType:@encode(CGAffineTransform)] or [NSValue valueWithCGAffineTransform:xform];Knavery
This is super-helpful, but note that it's iOS 8+ so if you are supporting iOS 7 or lower, you have to user @William Jockusch's solution.Centroclinal
P
2

Per the Core Image Filter Reference.

CGAffineTransform xForm = whatever;
[myFilter setValue:[NSValue valueWithBytes:&xForm objCType:@encode(CGAffineTransform)] forKey:@"inputTransform"];
Patrica answered 18/10, 2012 at 16:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.