Apply GPUImage filter to a UIView

谁说我不能喝 提交于 2019-12-07 10:52:48

问题


I've a problem. I need to apply a filter like Pixelate or Blur to an entire UIView. Like the eBay iPad app.

I thought to use GPUImage but I don't know how to do it. There is a way to apply a filter to a GPUImageView directly without pass a UIImage?

The primary problem is that making a screenshot of a large UIView on an iPad 3rd is to expensive (2 seconds for the UIWindow grab). So the perfect solution is to apply filter directly to the views, just like eBay app, but.. how?

Thanks to all!


回答1:


To pull a view into GPUImage, you can use a GPUImageUIElement source, which takes a UIView or CALayer as input. There's an example of this in the FilterShowcase sample application.

This does rely on the -renderInContext: method of an underlying CALayer, which can be expensive for redrawing the view. However, if the view is static, you just need to use this update once and the resulting image will be cached on the GPU as a texture. Filter actions applied to it after that point will be very fast.




回答2:


You might be able to achieve the look you are after by applying CIFilters to your views layer.filters property. Check the docs for more info:

https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html




回答3:


Maybe this is something for you? Haven't tried it but read about it in a post once:

StackBlur

Ow sorry, I read your post again and this extension is about blurring an UIImage, and you said that this was something you didn't want... Well I'll leave it here anyways if people go googling for blurring an image.. Sorry :(



来源:https://stackoverflow.com/questions/13968233/apply-gpuimage-filter-to-a-uiview

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