I am attempting to draw "pixelated" or "vectorized" lines that look like this style:
Ideally I am trying to draw a path via something like CAShapeLayer and have the path be pixelated to this style. It doesn't need to look super great like an actual asset but it needs to follow that general style. I have tried several approaches and got pretty close with a result is on the right track here:
The only issue I have now is removing the blur applied to the way I attempted to do this. I need my result to be pixelated but still very crisp, this is my most recent approach used to get the effect above:
let path = UIBezierPath(roundedRect: bounds, cornerRadius: 20)
let lay = CAShapeLayer()
lay.path = path.cgPath
lay.strokeColor = UIColor.green_bright.cgColor
lay.lineWidth = 5
lay.fillColor = nil
lay.shouldRasterize = true
lay.rasterizationScale = 0.1
layer.addSublayer(lay)
I have also attempted using CIFilters like CIPixellate but cannot figure out how you can apply a filter like this to a CAShapeLayer or path in any way.
Is there any way to clean this method up or any other way to achieve this type of effect? All feedback or ideas are appreciated.
UPDATE: I am attempting to use filters by turning my layer into an image and applying a CIFilter, here is how I am unsuccessfully trying:
extension CAShapeLayer {
func apply(_ filter: String) -> UIImage? {
let context = CIContext(options: nil)
let renderer = UIGraphicsImageRenderer(size: frame.size)
if let currentFilter = CIFilter(name: filter) {
let image = renderer.image { context in
render(in: context.cgContext)
}
let beginImage = CIImage(image: image)
currentFilter.setValue(beginImage, forKey: kCIInputImageKey)
if let output = currentFilter.outputImage {
if let cgimg = context.createCGImage(output, from: output.extent) {
return UIImage(cgImage: cgimg)
}
}
}
return nil
}
}