问题
I need a reliable, efficient method to create iOS 7 blur effect. I've implemented Apple's applyBlurWithRadius
from WWDC code (UIImage+ImageEffects)
. It is pretty flexible actually, it allows to change tintColor
also which provides to create a darker blur effect like this:
But it relies on the Core Graphics and it is decreasing the scrolling performance in a table view. Then I've seen BradLarson's GPUImage library and it's GPUImageiOSBlurFilter
method which replicates the iOS 7 effect and it works much faster than the UIImage+ImageEffects
, so it seems more usable in my case.
But the problem is, it doesn't has any parameter like tintColor
. It creates whity effect like here. Also there are other filters of GPUImage but I'm not sure I can get the effect that I want.
回答1:
As I describe in the comments here, the "whitening" effect that the GPUImageiOSBlur filter provides is due to a luminance range restriction that I apply in the last step of that operation. The filter itself is a grouped filter, where the image is first desaturated and downsampled, Gaussian blurred, and then upsampled and luminance range restricted in the last step.
That last step is performed using a GPUImageLuminanceRangeFilter, which I built to replicate the exact effect that Apple seems to apply to most of their overlay blurs. They appear to use a different color effect in others, though, so to mimic that you'll want to change that last step in the filter.
I might make this something that the user can specify as a tint color later on, but for now you can create your own custom filters based on GPUImageiOSBlurFilter and GPUImageLuminanceRangeFilter, and change your implementation of GPUImageLuminanceRangeFilter to alter the final colors to be darker than what is provided normally. You'll have to experiment with the values in that fragment shader to see what produces the effect you want.
Other people have done this, to good effect, but none have fed it back in as a pull request yet.
来源:https://stackoverflow.com/questions/23193358/gpuimage-darker-ios-7-blur-effect