How do you create a 'blurred text' image effect in iOS? - ios

I want to create a text shaped blur effect to an image as shown below:
Another example:
I have found an answer on blurring a UILabel answer: How to blur UILabel text.
But the effect is not correct.
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:
Besides, I also want to apply this kind of blur effect into photo's watermark.
So, any help?

You're going to need a two stage approach to get the desired effect:
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.
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.

Related

Draw Image to Canvas with Color

I use canvas.drawImageRect to draw an image to a canvas.
The image itself is just white with transparency, but I want it to have another color. I tried creating a Paint with the color set to yellow but that didn't made the image appear yellow.
I guess there is a way to do this, can anyone tell me?
Create a Paint and add a ColorFilter.
ColorFilter.mode(Color color, BlendMode blendMode)
Creates a color filter that applies the blend mode given as the second argument. The source color is the one given as the first argument, and the destination color is the one from the layer being composited.
I think you want srcATop BlendMode.

How do I set tint color only for non white parts of the UIImage?

Simple I have UIImageView icon with two people and it looks like this:
but when I set tintColor to red it looks like this:
Is there any way to avoid covering every non zero-alpha pixel? I need to show the tie really there. One time I need people red, other time green.
The icon is simple png file. Rounded circle is simple background color of UIImageView. So the part of the image with tie cannot be zero-alpha.
Is there any way to achieve such effect WITHOUT creating images for every color?
This was similar to another idea I had been playing around with, so I did a little more fiddling...
Starting with these 3 images:
and then using them as .withRenderingMode(.alwaysTemplate) to give the desired colors... and then layering them via CALayer to get:
and an "exploded" view for clarity...
Create an image where the "people" are 100% transparent - effectively "holes" in the image.
Set the background color of the UIImageView to be the "fill" color.
You can still mask it with a circle (CAShapeLayer, for example), if you don't want a white bounding-box as part of the image.
Original images:
https://i.stack.imgur.com/eFrmB.png
https://i.stack.imgur.com/2GNDX.png
Use the CISpotColor filter:
https://developer.apple.com/library/content/documentation/GraphicsImaging/Reference/CoreImageFilterReference/#//apple_ref/doc/filter/ci/CISpotColor
This allows you to specify a color in your image that is to be changed into another color. Thus, since you know the original color of the tie and the background, you can change either of them, or both, in a single move.

Mask/crop an image

What is the best approach to display a cropped/masked image in Flutter?
Lets say I have one image with a mask (eg. an irregular star shape with transparent background) and the other image which I want to mask with this star, so that only the part inside the star of original image would be rendered.
I'm aiming for something like PorterDuffXfermode on Android (similar question here - Android how to apply mask on ImageView?).
In case of simple mask shapes is going the RenderClipOval way a good approach?
I would just paint it using a CustomPainter, setting the Paint.BlendMode on the Paint you pass to the method when you paint the image.
See https://docs.flutter.io/flutter/dart-ui/Canvas/drawImageRect.html and https://docs.flutter.io/flutter/dart-ui/Paint/blendMode.html and https://docs.flutter.io/flutter/widgets/CustomPaint-class.html.

UIImage with Gradient iOS

Is it possible apply a gradient like this for iOS?
The gradient is applied to the image and it should lose focus. I can get the result for the background with CAGradientLayer but the image always has the same focus.
Maybe you can find useful applying some technics for image resizing in order to achieve the focus you want.
http://nshipster.com/image-resizing/

Objective-c how to create lens flare effect in iOS

I would like to create the same effect that you can see on the picture attached.
I would like to have that kind of effect over my barcode scanner, which scan barcode with phone camera.
Any idea how can I do this?
I already tried with shadows but that was not the effect I want.
Thank you.
It looks like the
CILenticularHaloGenerator core image filter simulates lens flare, although the appearance is different than what you show.
Your image looks more like a radial gradient in red drawn over your image. You could use the Core Image CIRadialGradient filter, or overlay a partly transparent gradient on top of your image using CGGradient and CGContextDrawRadialGradient.

Resources