【问题标题】:Can I convert an image into a grid of dots?我可以将图像转换为点网格吗?
【发布时间】:2012-07-31 06:18:00
【问题描述】:

只是一个简单的问题。

这个可以吗:

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

【问题讨论】:

    标签: iphone ios image image-processing


    【解决方案1】:

    简短的回答是:是的,但目前我不确定具体使用哪个框架。 注意:你刚刚问是否可能,我给出了你的问题的答案,而不是如何去

    【讨论】:

    【解决方案2】:

    您应该能够做到这一点,只需循环并绘制黑白圆圈,然后使用该图像作为图像的蒙版。

    这是我在 Google 上找到的关于 CoreGraphics 遮罩的第一个链接,您可以根据自己的需要进行调整:http://cocoawithlove.com/2009/09/creating-alpha-masks-from-text-on.html

    我想画很多圆圈是你可以通过自己的谷歌搜索找到的。

    【讨论】:

    • 感谢您的回复。那是一个聪明的解决方案。现在我只需要“像素化”图像......有什么建议吗?
    • 我不知道是否有一个简洁的 CoreGraphics API 可以为您像素化(也许有,但我只是找不到)。你可以做最简单的实现,只是缩小图像然后再放大。如果这对您的需求来说效率太低,这里有一些关于更有效算法的讨论:stackoverflow.com/questions/1987054/…
    【解决方案3】:

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

    这是我刚刚添加到我的开源 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);
     }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-14
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 2023-04-06
      • 1970-01-01
      • 2021-03-12
      • 2011-10-30
      相关资源
      最近更新 更多