如何在Android中实现阻力变形图像滤镜? [英] How to implement Drag Distortion Image filter in android?

查看:110
本文介绍了如何在Android中实现阻力变形图像滤镜?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究自定义图像过滤器项目.而且我遇到了一项具有挑战性的任务,在该任务中,我应该应用变形的过滤器,如

I am working on custom image filter project. And I came across one challenging task, in which I am supposed to apply distorted filters as can be seen in Funny face effect app. I want to develop first 3 filters as available in Funny Face Effects.

为了实现这种效果,我开始使用GPUImageView GPUImage ,在此过程中,它使用了搜索栏使图像偏离中心.由此,我实现了凸出失真. 但是,有什么方法可以实现拖动过滤器,从而可以通过拖动手势使图像变形?

So to implement such an effect I started using GPUImageView GPUImage and in this, it is using seekbar to distort image from the centre. I have achieved Bulge distortion from this. But is there any way I can implement drag filter, where I can distort my image by drag gesture?

我们尝试搜索GPUImage以外的任何其他第三方类.但是我们找不到有用的东西.

We tried to search for any other third party classes other then GPUImage. But we could not find useful stuff.

我们的查询如下:-

1)是否可以使用拖动"手势应用拖动过滤器"? (任何代码段或参考均可)

1) Is it possible to apply Drag filter using Drag gesture? (Any code snippet or reference appreciable)

2)除GPU之外的任何其他第三方类别都可以帮助我们获得上述结果.

2) Any other third party class other than GPU which can help us to get above results.

提前谢谢!

推荐答案

一种实现方法是使用其他纹理向片段着色器指定要应用的变形.您可以在用户触摸图像以应用变形时从应用程序修改该纹理内容.

One way to achieve it is to use an additional texture to specify to the fragment shader the deformation to apply. You can modify that texture contents from the app as the user touches the image to apply deformations.

GPUImageBulgeDistortionFilter 扩展了

GPUImageBulgeDistortionFilter extends GPUImageFilter which is designed to use only one texture.

您将需要在GPUImageFilter中复制纹理绑定(glBindTexture)和分配给片段着色器(glUniform1i),并使用1作为新纹理(而不是0).您还需要复制glGetUniformLocation并使用其他名称代替inputImageTexture,例如inputImageTexture2.

You'll need to duplicate the texture binding (glBindTexture) and assignation to the fragment shader (glUniform1i) in GPUImageFilter using 1 for the new texture (instead of 0). You'll need also to duplicate glGetUniformLocation and use other name instead of inputImageTexture, for example inputImageTexture2.

在GPUImageBulgeDistortionFilter上修改片段着色器,或创建一个从GPUImageBulgeDistortionFilter派生的新类,以添加"uniform sampler2D inputImageTexture2; \ n" +

Modify the fragment shader at GPUImageBulgeDistortionFilter or create a new class derived from GPUImageBulgeDistortionFilter to add "uniform sampler2D inputImageTexture2;\n" +

最后添加代码以使用inputImageTexture2纹理元素在同一片段着色器中的inputImageTexture处变形数据.

Finally add code to use inputImageTexture2 texels to deform data at inputImageTexture in the same fragment shader.

这篇关于如何在Android中实现阻力变形图像滤镜?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆