Drawing simple lines on iPhone with CoreGraphics

后端 未结 5 2634
后悔当初
后悔当初 2021-02-20 18:09

I would like to draw a straight line between where a user touches the screen, and where the touch ends. i need multiple lines, for if the user repeats the touch-drag-release act

5条回答
  •  生来不讨喜
    2021-02-20 18:42

    The Problem is that UIGraphicsGetCurrentContext() will return a null-reference. If you want to draw into an UIImage you can get the CGContextRef as follows:

    UIGraphicsBeginImageContext(anUIImage);
    

    now calling UIGraphicsGetCurrentContext() will not longer return a null-reference.

    ... drawing goes here

    UIImage* drawnImage = UIGraphicsGetImageFromCurrentImageContext();
    // display the image on an view
    UIGraphicsEndImageContext();  
    

提交回复
热议问题