简体   繁体   English

如何使用CIFilter作为链接下的图像创建失真效果

[英]How to create distortion effect using CIFilter as the images under link

I'm looking to add an effect into my app (Live Filtering Recorder App) using core image filter. 我希望使用核心图像滤镜将效果添加到我的应用程序(Live Filtering Recorder App)中。 This effect needs to show distortion lines appearing just like old time recorders. 这种效果需要显示出失真线,就像旧的录音机一样。 I tried it by loading image frames and applying as overlay to the output of the filters image but that create a lag into the recording. 我尝试通过加载图像帧并将其作为叠加层应用到滤镜图像的输出来进行尝试,但这会给录制造成延迟。 So i'm not looking to generate this effect by CIFILTERS now. 因此,我现在不希望通过CIFILTERS产生这种效果。

Tape Recorder like Distortion Lines 像变形线一样的录音机

Thanks. 谢谢。

This looks like a job for a custom kernel. 这看起来像是自定义内核的工作。

You can generate a random noise field with CIRandomGenerator and then use some custom Core Image Kernel Language to composite it over your original image in stripes using sin to control the spacing. 您可以使用CIRandomGenerator生成一个随机噪声场,然后使用一些自定义的Core Image Kernel Language将其合成为原始条纹图像,并使用sin控制间隔。 Passing the sine of the vertical position through a smoothstep gives a nice effect. 通过smoothstep传递垂直位置的smoothstep会产生很好的效果。

You kernel should look something like: 您的内核应类似于:

    let kernel = CIColorKernel(string:
        "kernel vec4 vhsNoise(__sample image, __sample noise, float time, float spacing, float stripeHeight, float backgroundNoise)" +
            "{" +
            "   vec2 uv = destCoord();" +

            "   float stripe = smoothstep(1.0 - stripeHeight, 1.0, sin((time + uv.y) / spacing)); " +

            "   return image + (noise * noise * stripe) + (noise * backgroundNoise);" +
        "}"
        )!

I've actually written a CIFilter to do this which you can find here . 我实际上已经编写了一个CIFilter来做到这一点,您可以在这里找到

Simon 西蒙

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

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