How to implement Drag Distortion Image filter in android?

人盡茶涼 提交于 2019-12-03 11:19:15

问题


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.

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?

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

Our queries are as under:-

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

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

Thanks in advance!


回答1:


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 extends GPUImageFilter which is designed to use only one texture.

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.

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

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



来源:https://stackoverflow.com/questions/43279011/how-to-implement-drag-distortion-image-filter-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!