Reputation: 73
I have an imageView and i want to draw lines on image in that imageView using CGPoints but i am getting errors like: invalid context etc.. any solution to draw lines without CGContext approach.
CGContextRef cntxt = UIGraphicsGetCurrentContext();
CGContextMoveToPoint(cntxt, p1.x, p1.y);
CGContextAddLineToPoint(cntxt, p2.x, p2.y);
CGContextStrokePath(cntxt);
Thanks
Upvotes: 2
Views: 402
Reputation: 299345
You are likely attempting to draw outside of drawRect:
. If you check the value of cntxt
, it is likely NULL
. A draw context is created prior to calling drawRect:
and is destroyed afterwards. There is generally no "current context" outside of this function.
You need to keep track of your points in a data structure. In drawRect:
, you will then do whatever drawing you need to do based on that data.
Upvotes: 1