Dimitri Dimix Giani
Dimitri Dimix Giani

Reputation: 43

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!

Upvotes: 4

Views: 5347

Answers (3)

Brad Larson
Brad Larson

Reputation: 170309

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.

Upvotes: 8

Tark
Tark

Reputation: 5173

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

Upvotes: 1

Ron
Ron

Reputation: 1047

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 :(

Upvotes: 0

Related Questions