CITemperatureAndTint for image in iOS

六眼飞鱼酱① 提交于 2019-12-09 15:46:51

问题


Is there any sample code or example for CITemperatureAndTint? I have read its documentation but i need some example to implement it.


回答1:


CIFilter *yourFilter = [CIFilter filterWithName:@"CITemperatureAndTint"];
[yourFilter setValue:yourInputImage forKey:@"inputImage"];
[yourFilter setValue:[CIVector vectorWithX:6500 Y:500] forKey:@"inputNeutral"]; // Default value: [6500, 0] Identity: [6500, 0]
[yourFilter setValue:[CIVector vectorWithX:1000 Y:630] forKey:@"inputTargetNeutral"]; // Default value: [6500, 0] Identity: [6500, 0]
CIImage *resultImage = [yourFilter valueForKey: @"outputImage"];
UIImage *resultOutputImage = [UIImage imageWithCGImage:[context createCGImage:resultImage fromRect:resultImage.extent]];    

You can see what values for color temperature give you which colors in this wikipedia link.

For Reference

CITemperatureAndTint has three input parameters: Image, Neutral and TargetNeutral. Neutral and TargetNeutral are of 2D CIVector type, and in both of them, note that the first dimension refers to Temperature and the second dimension refers to Tint. What the CITemperatureAndTint filter basically does is computing a matrix that adapts RGB values from the source white point defined by Neutral (srcTemperature, srcTint) to the target white point defined by TargetNeutral (dstTemperature, dstTint), and then applying this matrix on the input image (using the CIColorMatrix filter). If Neutral and TargetNeutral are of the same values, then the image will not change after applying this filter. I don't know the implementation details about iPhoto, but I think the two slide bars give the Temperature and Tint changes (i.e. differences between source and target Temperature and Tint values already) that you want to add to the source image.




回答2:


well there is no specific example that is made for CITemperatureAndTint but you can get the code to demonstrates the use of an NSImage as an off-screen drawing destination.

The URL for that code is https://developer.apple.com/library/mac/#samplecode/Tinted_Image/Introduction/Intro.html#//apple_ref/doc/uid/DTS10000412-Intro-DontLinkElementID_2

I am sure you can modify it to use CITemperatureAndTint or modify the existing code to meet your needs.

Hope this helps.



来源:https://stackoverflow.com/questions/11464266/citemperatureandtint-for-image-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!