I'm trying to make a simple drawing app in swift, iOS.
So i've managed to draw using Path(). Now i want to save an image of what i've drawn.
I have found on apple docs that ImageRenderer() is the thing to use nowadays. But i can't seem to make it work with Path().
This renders just fine:
let renderer = ImageRenderer(content: Text("3"))
This doesn't:
let renderer = ImageRenderer(content: Path { path in
path.addLines(lines)
}.stroke(lineWidth: 5.0))
I've spent 3 days now with different methods and hacks, but nothing really works?
Why is it that cant render a path, which is a View with swifts ImageRenderer?
You can very well draw a Path instance. Your problem is that you are not actually stroking the path and so it looks empty. Let's fix that and also make sure that the path we draw fits nicely inside an image.
Testing this out we can draw a shape and then preview it as an image: