我的iOS设备没有使用CITemperatureAndTint和CIToneCurve进行任何处理
但是,如果CISepiaTone做得对!!
outputImage = [CIFilter filterWithName:@"CIToneCurve" keysAndValues:@"inputImage", image, @"inputPoint0", [CIVector vectorWithX:0 Y:0], @"inputPoint1", [CIVector vectorWithX:0.25 Y:0.25], @"inputPoint2", [CIVector vectorWithX:0.5 Y:0.5], @"inputPoint3", [CIVector vectorWithX:0.75 Y:0.75], @"inputPoint4", [CIVector vectorWithX:1 Y:1], nil].outputImage;
这有什么问题??
答案 0 :(得分:1)
使用此代码:它有效
- (UIImage*)applyToneCurve:(NSArray*)pointArray {
if ([pointArray count] < 2) {
return self;
}
CGPoint first = [[pointArray objectAtIndex:0] CGPointValue];
first.x /= 255.0;
first.y /= 255.0;
CGPoint firstPoint = first;
CGPoint last = [[pointArray lastObject] CGPointValue];
last.x /= 255.0;
last.y /= 255.0;
CGPoint fifthPoint = last;
CGPoint secondPoint = CGPointMake(0.25, 0.25);
CGPoint thirdPoint = CGPointMake(0.50, 0.50);
CGPoint fourthPoint = CGPointMake(0.75, 0.75);
for (int i = 1; i < [pointArray count] - 1; i++) {
CGPoint point = [[pointArray objectAtIndex:i] CGPointValue];
point.x /= 255.0;
point.y /= 255.0;
if (i == 1) {
secondPoint = point;
}
else if (i == 2) {
thirdPoint = point;
}
else if (i == 3)
fourthPoint = point;
}
CIImage *inputImage = [CIImage imageWithCGImage:self.CGImage];
CIFilter *toneCurveFilter = [CIFilter filterWithName:@"CIToneCurve"];
[toneCurveFilter setDefaults];
[toneCurveFilter setValue:inputImage forKey:kCIInputImageKey];
[toneCurveFilter setValue:[CIVector vectorWithX:firstPoint.x Y:firstPoint.y] forKey:@"inputPoint0"];
[toneCurveFilter setValue:[CIVector vectorWithX:secondPoint.x Y:secondPoint.y] forKey:@"inputPoint1"];
[toneCurveFilter setValue:[CIVector vectorWithX:thirdPoint.x Y:thirdPoint.y] forKey:@"inputPoint2"];
[toneCurveFilter setValue:[CIVector vectorWithX:fourthPoint.x Y:fourthPoint.y] forKey:@"inputPoint3"];
[toneCurveFilter setValue:[CIVector vectorWithX:fifthPoint.x Y:fifthPoint.y] forKey:@"inputPoint4"];
CIImage *outputImage = [toneCurveFilter outputImage];
CGImageRef ref = [[CIContext contextWithOptions:nil] createCGImage:outputImage fromRect:outputImage.extent];
UIImage *result = [UIImage imageWithCGImage:ref];
if (ref) {
CGImageRelease(ref);
}
return result;
}
PointArray从开始到结束包含5个NSValue曲线点。
答案 1 :(得分:0)
看起来很正确。您是否尝试过使用setDefaults进行初始化?
答案 2 :(得分:0)
正常色调曲线是从(0,0)到(1,1)的直线,它是输入值所构成的直线,是由'setDefaults'设置的直线。
正常色调曲线:
如果更改“inputPoints”以创建不同的曲线,您将看到正在应用的过滤器。如果是负面曝光,请尝试:
inputPoint0 = (0,1)
inputPoint1 = (0.25,0.75)
inputPoint2 = (0.5,0.5)
inputPoint3 = (0.75,0.25)
inputPoint4 = (1,0)
或者是非典型的一行: