I have two images, one that is a monochrome one which is a mask and another one with full color. What I need to do is find the CGRect of the mask (white pixels) in the other full color one.
What I did is to first find the contour of the mask using the Vision framework. Now, this returns a CGPath which is normalised. How can I translate this path into coordinates to the other image? Both have been scaled the same way to make them the same size so the translation should be "easy" but I can't figure it out.
I have a CAShapeLayer with an opaque stroke and a transparent fill. I then want to call myContext.drawRadialGradient, but have this radial gradient clip to the stroke of my shape layer. Currently, I'm calling myShapeLayer.path.addClip(), which clips the radial gradient to the fill region of the shape layer, instead of the stroke.
In other words, I'd like to use either just the opaque part of a layer or just the stroke (same thing in my case), and use it to clip the current context. I've been searching the CoreGraphics docs for a while to no avail.
Found my answer. You can create a new UIBezierPath that is a copy of your existing one, with a stroke, as below:
let strokePath = UIBezierPath(cgPath: oldPath.cgPath.copy(
strokingWithWidth: ..., lineCap: ..., lineJoin: ..., miterLimit: ...))
strokePath.addClip()
What if you add your shape layer as the mask of your gradient layer? That should work, since that's what a mask layer is supposed to do.
If that doesn't work you might need to capture your shape layer to an image and install THAT as the mask of your gradient layer.
Convert the stroked path to a new path whose fill area is the same as the original stroke. Now you have a fillable area that you can use as clipping area. The CGContext way to do this is by calling replacePathWithStrokedPath. As the docs explicitly say:
For example, you can clip to the stroked version of a path by calling this function followed by a call to the function clip().
I have one requirement to show the a shape (like Home or Car etc) and depending upon the percentage of the condition will be filled with animation
I was trying with image but when I googled, I found this can be achieved by drawing image using Bezier curve.
So this is the image I am trying to draw and there are other images too.
So here are my two questions :
Can I achieve this using UIImage directly.
If not then how can i draw bezier
curve for such images. How will I calculate the points.
I have drawn a path on a view, All I need is to apply a gradient blur effect from the outer edge of the closed drawn path to the view's bounds. My question is mainly about the Gradient blur effect rather than applying it on the path.
I've not tried this but believe you could make it work:
create the path
use the path as a mask can create an new image that is clear outside the path while selecting the interior of the path (the interior has to be opaque)
use a radial blur on the whole image
composite the saved interior path OVER the blurred image
stroke the path to get a clear definition between the original interior and the blurred exterior
I need to display image with rounded corner with sprite. What is the best way to do this.
I explained how to do it in your other post ...
How to clip the texture in rounded shape
If you mean of smoothing the corners of the image you're drawing, there is no way to do with the normal sprite interface (other than modifying the original image to be smoothed beforehand)
To do it you must work with shaders.