gpt4 book ai didi

iphone - 我可以将图像转换为点网格吗?

转载 作者:行者123 更新时间:2023-12-01 18:27:49 26 4
gpt4 key购买 nike

只是一个快速的问题。

可以这样:

Polka Dot Image

在 iOS 设备上完成图像处理?如果是,如何?

最佳答案

是的,尽管 Core Graphics 可能不是对图像进行此类过滤的最佳方式。我的建议是使用 OpenGL ES 2.0 片段着色器。事实上,我只是写了一个来做到这一点:

Polka dot image conversion

这是我刚刚添加到我的开源 GPUImage 中的 GPUImagePolkaDotFilter框架 。使用它的最简单方法是获取框架并将过滤器应用于您想要的任何内容(它足够快以在视频上实时运行)。

如果您只想使用片段着色器,以下是我的代码:

 varying highp vec2 textureCoordinate;

uniform sampler2D inputImageTexture;

uniform highp float fractionalWidthOfPixel;
uniform highp float aspectRatio;
uniform highp float dotScaling;

void main()
{
highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio);

highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor;
highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
highp vec2 adjustedSamplePos = vec2(samplePos.x, (samplePos.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
highp float distanceFromSamplePoint = distance(adjustedSamplePos, textureCoordinateToUse);
lowp float checkForPresenceWithinDot = step(distanceFromSamplePoint, (fractionalWidthOfPixel * 0.5) * dotScaling);

gl_FragColor = vec4(texture2D(inputImageTexture, samplePos ).rgb * checkForPresenceWithinDot, 1.0);
}

关于iphone - 我可以将图像转换为点网格吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11774720/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com