使用 CIGaussianGradient 滤波器进行核心图像的示例

发布于 2024-12-14 04:02:27 字数 837 浏览 4 评论 0原文

我正在寻找适用于 iOS 的 Core Image 过滤器的代码示例。参数中带有 inputImage 的那些过滤器,我可以弄清楚如何实现。但是那些没有 inputImage 参数的,我不确定它是如何工作的。

以下是 Apple 文档的摘录:

CIGaussianGradient

使用高斯分布生成从一种颜色到另一种颜色变化的渐变。 参数

inputCenter

A CIVector class whose attribute type is CIAttributeTypePosition and whose display name is Center.

Default value: [150 150] Identity: (null) 

inputColor0

A CIColor class whose display name is Color 1.

inputColor1

A CIColor class whose display name is Color 2.

inputRadius

An NSNumber class whose attribute type is CIAttributeTypeDistance and whose display name is Radius.

Default value: 300.00 Minimum: 0.00 Maximum: 0.00 Slider minimum: 0.00 Slider maximum: 800.00 Identity: 300.00

I am looking for a code sample of this Core Image filter for iOS. Those filters with the inputImage in the parameter, I can figure out how to implement. But the ones without the inputImage parameter, I am not sure how it works.

Here is the extract from Apple's doc:

CIGaussianGradient

Generates a gradient that varies from one color to another using a Gaussian distribution.
Parameters

inputCenter

A CIVector class whose attribute type is CIAttributeTypePosition and whose display name is Center.

Default value: [150 150] Identity: (null) 

inputColor0

A CIColor class whose display name is Color 1.

inputColor1

A CIColor class whose display name is Color 2.

inputRadius

An NSNumber class whose attribute type is CIAttributeTypeDistance and whose display name is Radius.

Default value: 300.00 Minimum: 0.00 Maximum: 0.00 Slider minimum: 0.00 Slider maximum: 800.00 Identity: 300.00

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海夜未眠 2024-12-21 04:02:27

这应该可以帮助您开始......尽管我不确定为什么这会在 iOS 中产生洋红色超过白色的渐变,而它在 Quartz Composer 中产生洋红色超过黑色的渐变。 (如果你还没有使用过 Quartz Composer,它包含在 Apple 的开发工具中,非常适合测试 Core Image 滤镜)

要使用它做任何有用的事情,我相信你必须在之后裁剪它 - 否则它将具有无限的维度(根据到 Quartz Composer)。

// set up the parameters for the filter
CIVector *centerVector = [CIVector vectorWithX:150 Y:150];
CIColor *color0 = [CIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:1.0];
CIColor *color1 = [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
NSNumber *radius = [NSNumber numberWithFloat:300.0];

// create a CIImage and apply the filter
CIImage *theCIImage = [[CIImage alloc] init];
theCIImage = [CIFilter filterWithName:@"CIGaussianGradient" keysAndValues:@"inputCenter", centerVector, @"inputColor0", color0, @"inputColor1", color1, @"inputRadius", radius, nil].outputImage;

// crop the image using CICrop
CGRect rect = CGRectMake(0.0, 0.0, 600.0, 600.0);
theCIImage = [CIFilter filterWithName:@"CICrop" keysAndValues:kCIInputImageKey, theCIImage, @"inputRectangle", rect, nil].outputImage;

This should get you started... though I'm not sure why this produces a magenta over white gradient in iOS, while it produces a magenta over black gradient in Quartz Composer. (if you haven't used Quartz Composer, it's included with Apple's dev tools and is great for testing out Core Image filters)

To do anything useful with it, I believe you have to crop it afterwards - otherwise it will have infinite dimensions (according to Quartz Composer).

// set up the parameters for the filter
CIVector *centerVector = [CIVector vectorWithX:150 Y:150];
CIColor *color0 = [CIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:1.0];
CIColor *color1 = [CIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
NSNumber *radius = [NSNumber numberWithFloat:300.0];

// create a CIImage and apply the filter
CIImage *theCIImage = [[CIImage alloc] init];
theCIImage = [CIFilter filterWithName:@"CIGaussianGradient" keysAndValues:@"inputCenter", centerVector, @"inputColor0", color0, @"inputColor1", color1, @"inputRadius", radius, nil].outputImage;

// crop the image using CICrop
CGRect rect = CGRectMake(0.0, 0.0, 600.0, 600.0);
theCIImage = [CIFilter filterWithName:@"CICrop" keysAndValues:kCIInputImageKey, theCIImage, @"inputRectangle", rect, nil].outputImage;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文