如何使用OpenGL ES对UIImage应用扭曲? [英] How can you apply distortions to a UIImage using OpenGL ES?

查看:135
本文介绍了如何使用OpenGL ES对UIImage应用扭曲?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在iPhone应用程序中使用OpenGL ES在UIImage上创建像凹痕,捏,扭曲,挤压等效果 PhotoTwist

Is there any way to create effects like dents, pinching, twisting, squashing, etc. on a UIImage using OpenGL ES as in the iPhone application PhotoTwist?

是否有任何参考或指导方针?我不想要代码,只是如何做到这一点的参考。

Are there any references or guidelines for doing this? I don't want code, just a reference on how to do this.

推荐答案

这种方式最有效的方法图像处理将使用OpenGL ES 2.0着色器。再一次,如果我可以指向您的 GPUImage 框架,它可以执行您描述的许多失真操作。对于那些缺失的人,你可以编写自己的片段着色器。

The most performant way of doing this kind of image processing would be to use OpenGL ES 2.0 shaders. Once again, if I might point you to my GPUImage framework, it can do many of the distortion operations you describe. For those that are missing, you can write your own fragment shaders.

我在那里的效果是凸起的凸起失真(使用GPUImageBulgeDistortionFilter):

The effects I have in there are a convex bulge distortion (using a GPUImageBulgeDistortionFilter):

凹陷失真(使用前一过滤器的反转比例参数):

a concave distortion (using an inverted scale parameter to the previous filter):

旋涡失真(使用GPUImageSwirlFilter):

a swirl distortion (using the GPUImageSwirlFilter):

最后,捏合失真(使用GPUImagePinchDistortionFilter):

and finally, a pinch distortion (using the GPUImagePinchDistortionFilter):

如果你看一下每个过滤器使用的着色器,你会发现它们之间的数学非常相似。您应该能够调整它以从同一个基础生成自己的自定义效果。

If you look at the shaders used for each of the filters, you'll find that the math is very similar between them. You should be able to tweak that to produce your own custom effects from this same base.

将这些过滤器应用于UIImages相当容易。如果您只想使用一个过滤器,则可以执行以下操作:

It's fairly easy to apply these filters to UIImages. If you have just one filter you'd like to use, you can do something like the following:

UIImage *inputImage = [UIImage imageNamed:@"test.jpg"];
GPUImageBulgeDistortionFilter *stillImageFilter = [[GPUImageBulgeDistortionFilter alloc] init];
UIImage *quickFilteredImage = [stillImageFilter imageByFilteringImage:inputImage];

这将从磁盘创建UIImage,使用OpenGL ES对其进行过滤,并返回已过滤的UIImage你要合作。如果您想要执行更高级的链式效果,可以使用GPUImagePicture和自定义过滤器管道,或者您可以使用其他输入源过滤实时相机视频或电影。

This will create a UIImage from disk, use OpenGL ES to filter it, and return a filtered UIImage for you to work with. You can use a GPUImagePicture and a custom filter pipeline if you'd like to perform more advanced chained effects, or you can use a different input source for filtering live camera video or movies.

此项目的源代码可在BSD许可证的上述链接中获得,因此您可以深入了解如何与OpenGL ES之间传输数据以及如何执行这些类型的过滤器。

The source code for this project is available at the above link under a BSD license, so you can dig into it to see how to transfer data to and from OpenGL ES and how to perform these kinds of filters.

这篇关于如何使用OpenGL ES对UIImage应用扭曲?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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