BlackMouse
BlackMouse

Reputation: 4572

IOS: Adding blur to a UIImage without clipping the blur

Is it possible to generate a blurred image without it being clipped to the edge of the view? As you can see in the image below, the right side isn't clipped (since the frame stretches out beyond that blur), but the left side is.

Thanks in advance

enter image description here

    GPUImageMotionBlurFilter *blurFilter = [GPUImageMotionBlurFilter new];
    blurFilter.blurSize = 10;
    blurredImage = [blurFilter imageByFilteringImage:blurredImage];

Upvotes: 1

Views: 169

Answers (1)

Brad Larson
Brad Larson

Reputation: 170309

An image processing operation can only extend out as far as the size of the image, so what you'll need to do is resize the canvas over which this is operating.

Using GPUImage, the first way that comes to mind is to increase the resolution of the image using -forceProcessingAtSize:, then use an inverse transform to place your image in its original resolution at the center of that. For example, if you doubled the size of your original image, you'd then do a scaling transform of 0.5 in X and Y, and a translation of 0.25 in X and Y (you might want to check the math and polarities on that, though).

You may also need to set the background of your transform filter to match that of your image (white, in this case) using -setBackgroundColorRed:green:blue:alpha:, otherwise you'll get a black area by default outside of the dimensions of your original image.

One you've resized the image within the center of your area, you'd apply a blur to that, which will now cause the blur to extend past the limits of your original image.

Upvotes: 2

Related Questions