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

标签 iphone ios image image-processing

只是一个快速的问题。

可以这样:

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/

相关文章:

iPhone didFinishLaunchingWithOptions 方法

iphone - 在 ios 中使用 Graph Api 在 friend 墙上发帖不起作用

ios - 来自抽屉导航的 UIViewController 之间的转换

ios - 如何限制应用程序仅在 iPhone 中下载而不在 iPad 中下载

html - 添加了两个内联 block gif 图像,该行的背景颜色发生变化?

iphone - 使用批量请求在 Facebook 上传多张照片

iOS:将 View 转换为圆柱形

c# - 动态创建图像

javascript - 当图像尺寸大于最小标准时拖动图像

iphone - 一个 View Controller 中的多个 UIActionSheet