Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply GPUImage filter to a UIView

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!

like image 715
Dimitri Dimix Giani Avatar asked Jan 15 '23 17:01

Dimitri Dimix Giani


1 Answers

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.

like image 144
Brad Larson Avatar answered Jan 21 '23 03:01

Brad Larson