Can I convert an image into a grid of dots?

后端 未结 3 1775
闹比i
闹比i 2021-01-25 09:22

Just a quick question.

Can this:

\"Polka

be done with image processing on an iOS device

相关标签:
3条回答
  • 2021-01-25 09:46

    Yes, although Core Graphics may not be the best way to do such filtering on an image. My recommendation would be to use an OpenGL ES 2.0 fragment shader. In fact, I just wrote one to do this:

    Polka dot image conversion

    This is the GPUImagePolkaDotFilter that I just added to my open source GPUImage framework . 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);
     }
    
    0 讨论(0)
  • 2021-01-25 10:00

    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

    0 讨论(0)
  • 2021-01-25 10:01

    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

    I'd imagine drawing lots of circles is something you can figure out with some Googling of your own.

    0 讨论(0)
提交回复
热议问题