BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.23k stars 4.61k forks source link

Is it possible to filter a UIView? #2268

Open szxinyu opened 8 years ago

szxinyu commented 8 years ago

I created a UIView as a container, and there are a bunch of subviews that can be moved and resized inside the container. And the problem is that how to filter the container UIView and all its subviews at the same time (subviews might be moved/resized, so filtering a screenshot on every movement of the the subviews is too slow).

Any suggestion would be great!! Thank you

mrengine commented 8 years ago
GPUImageUIElement *pic1 = [[GPUImageUIElement alloc]initWithView:uiView];
GPUImageView *gpuImageView = [[GPUImageView alloc] initWithFrame:[uiView frame]];
[self.view addSubview:gpuImageView];

GPUImageToonFilter *filter = [GPUImageToonFilter new];
[pic1 addTarget:filter];
[filter addTarget:gpuImageView];
[pic1 update];
szxinyu commented 8 years ago

@mrengine thank you so much for your suggestion!! I tried your solution, and it only filters the view of GPUImageUIElement, it does not filter the subviews (subviews that contains other subviews) of a UIView... Or did I do anything wrong...

Thetiso commented 8 years ago

@mrengine i add sublayer (avplayerlayer ) to uiview,and use your solution to filter the calyer, it doesn't work!

BradLarson commented 8 years ago

GPUImageUIElement relies on calling -renderInContext: on the layer for whatever UI element you use. -renderInContext: renders Core Graphics drawing and can do limited amounts of layering, but it doesn't take into account many manipulations you can apply to sublayers and it doesn't render many types of layers (AV Foundation playback, OpenGL ES, etc.).

At the time I wrote this, there wasn't another way of capturing the contents of layers in a way that could be uploaded into a texture. If another way has emerged since then, this could be updated to use it.