I get the point from touch screen , and scale the point ,then I put the point to the UIBezierPath
,
this is my code
let bezierPath = UIBezierPath()
for var i:Int = 0 ; i < newPoints.count ; i++ {
var indexCount = 0
let point = newPoints[i][j]
if point.count > 0{
let newPointX = point[0] - originRectX // reset the point start with CGPointZero
let newPointY = point[1] - originRectY
let scalePointX = newPointX * heightScale //scale the point with heightScale 0.25
let scalePointY = newPointY * heightScale
let scalePoint = CGPointMake(scalePointX, scalePointY)
if indexCount == 0 {
bezierPath.moveToPoint(scalePoint)
}else{
bezierPath.addLineToPoint(scalePoint)
}
indexCount++
}
}
then I convert the path to UIImage
var tempImage = UIImage()
UIGraphicsBeginImageContextWithOptions(size, false, 1)
stokeColor.setStroke()
bezierPath.lineWidth = lineWidth
bezierPath.lineCapStyle = CGLineCap.Round
bezierPath.lineJoinStyle = CGLineJoin.Round
bezierPath.stroke()
tempImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
then I draw the UIImage in screen
let context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context)
let rect = CGRect(x: drawObj.points![0].x,y: drawObj.points![0].y,width: drawObj.image.size.width,height: drawObj.image.size.height)
drawObj.image?.drawInRect(rect)
CGContextRotateCTM(context,CGFloat(Double(drawObj.angle!)*M_PI/180))
CGContextRestoreGState(context)
this is effect
You can find it is not smooth