Untitled
Guest 661 16th Dec, 2021
func drawLine(coords: Array<Int>) {
UIGraphicsBeginImageContext(canvas.bounds.size)
canvas.draw(canvas.bounds)
let ctx=UIGraphicsGetCurrentContext()
ctx?.move(to: CGPoint(x: coords[0], y: coords[1]))
ctx?.addLine(to: CGPoint(x: coords[2], y: coords[3]))
ctx?.setLineWidth(3)
ctx?.setStrokeColor(UIColor.black.cgColor)
ctx?.strokePath()
canvas.image=UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
func drawCircle(coords: Array<Int>) {
UIGraphicsBeginImageContext(canvas.bounds.size)
canvas.draw(canvas.bounds)
let ctx=UIGraphicsGetCurrentContext()
let rect = CGRect(x: coords[0], y: coords[1], width: coords[2], height: coords[3])
ctx?.setStrokeColor(UIColor.black.cgColor)
ctx?.setFillColor(UIColor.white.cgColor)
ctx?.setLineWidth(3)
ctx?.addEllipse(in: rect)
ctx?.drawPath(using: .fillStroke)
canvas.image=UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
To share this paste please copy this url and send to your friends
RAW Paste Data