Monday, 23 December 2019

drawing on canvasImageView is not working properly

if i am trying to draw beyond the canvasImageView frame then lines are drawing but if i am touching in the middle of the canvasImageView its not working at all . i have hierarchy mainView then view then scrollview then canvasView then imageView then canvasImageView to draw the line

fileprivate func drwaagain(lineappend : [[CGPoint]]) {
    // 1
    let canvasSize = canvasImageView.frame.size


    UIGraphicsBeginImageContextWithOptions(canvasSize, false, 0)


    if let context = UIGraphicsGetCurrentContext() {



        canvasImageView.image?.draw(in: CGRect(x: 0, y: 0, width: canvasSize.width, height: canvasSize.height))


        if(isDrawing)
        {
        lineappend.forEach { (lineappend) in
            for (i, p) in lineappend.enumerated() {


                if i == 0 {
                    context.move(to: p)


                } else {
                    context.addLine(to: p)
                }
            }
        }

        }
        else
        {
            lineremove.forEach { (lineremove) in
                for (i, p) in lineremove.enumerated() {
                    if i == 0 {
                        context.move(to: p)
                    } else {
                        context.addLine(to: p)
                    }
                }
            }
        }


        // 3
        context.setLineCap( CGLineCap.round)
        context.setLineWidth(3.0)
        if(isDrawing)
        {
            context.setStrokeColor(drawColor.cgColor)
            context.setBlendMode( CGBlendMode.normal)

        }
        else
        {

            context.setBlendMode(CGBlendMode.clear)
        }
        context.strokePath()

        canvasImageView.image = UIGraphicsGetImageFromCurrentImageContext()
    }
    UIGraphicsEndImageContext()
}


from drawing on canvasImageView is not working properly

No comments:

Post a Comment