0

I want to create a text shaped blur effect to an image as shown below: enter image description here

Another example:

enter image description here

I have found an answer on blurring a UILabel answer: How to blur UILabel text. But the effect is not correct.

enter image description here

So, How can I create a blurred text image effect that I can render into an image as a watermark in Swift?

Somebody help me! Thanks very much!

By the way, the answers about UIVisualEffectView is not correct. The effect using UIVisualEffectView is like:

enter image description here

Besides, I also want to apply this kind of blur effect into photo's watermark.

So, any help?

Community
  • 1
  • 1
Chris Forever
  • 678
  • 1
  • 5
  • 18

1 Answers1

0

You're going to need a two stage approach to get the desired effect:

  1. Generate a black and white image of the text (black background, white text). The standard string in Swift has a Draw method. There's another Answer that has more detail on this.
  2. Pass this 'text' image and your source image into the CIMaskedVariableBlur filter from CoreImage.

Basically, your 'text' image will act as the mask for the blur filter. Where the mask is lighter, the blur is stronger, and where the mask is black, no blur is applied.

Community
  • 1
  • 1
tebs1200
  • 1,205
  • 12
  • 19