简体   繁体   English

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

[英]Can I convert an image into a grid of dots?

Just a quick question. 只是一个简单的问题。

Can this: 可以这样:

波尔卡圆点图像

be done with image processing on an iOS device? 在iOS设备上完成图像处理? If yes, how? 如果有,怎么样?

Yes, although Core Graphics may not be the best way to do such filtering on an image. 是的,虽然Core Graphics可能不是对图像进行此类过滤的最佳方式。 My recommendation would be to use an OpenGL ES 2.0 fragment shader. 我的建议是使用OpenGL ES 2.0片段着色器。 In fact, I just wrote one to do this: 事实上,我刚写了一个这样做:

圆点图像转换

This is the GPUImagePolkaDotFilter that I just added to my open source GPUImage framework . 这是我刚刚添加到我的开源GPUImage框架的GPUImagePolkaDotFilter The easiest way to use it is to grab the framework and apply the filter to whatever you want (it's fast enough to run in real time on video). 使用它的最简单方法是获取框架并将过滤器应用于您想要的任何内容(它足够快以便在视频上实时运行)。

If you'd just like to use the fragment shader, the following is my code for this: 如果您只想使用片段着色器,以下是我的代码:

 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);
 }

You should be able to do this just by looping and drawing the circles in black and white, and then using that image as a mask for your image. 您应该能够通过循环和绘制黑白圆圈,然后使用该图像作为图像的蒙版来完成此操作。

Here's the first link I found on Google about CoreGraphics masking, which you can probably adapt for your needs: http://cocoawithlove.com/2009/09/creating-alpha-masks-from-text-on.html 这是我在Google上发现的第一个关于CoreGraphics屏蔽的链接,您可以根据自己的需要调整它: http//cocoawithlove.com/2009/09/creating-alpha-masks-from-text-on.html

I'd imagine drawing lots of circles is something you can figure out with some Googling of your own. 我想你可以通过自己的一些谷歌搜索来绘制很多圆圈。

SHORT Answer is: YES, but exactly using which framework i'm not sure for the moment. 简短回答是:是的,但确切地使用了我目前不确定的框架。 Note: Yo have just asked if it is possible, i gave the anwer for your question, not for how to go 注意:哟刚问过是否有可能,我给了你的问题,而不是如何去

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM