how to draw / doodle line on UIImage in swift?

前端 未结 3 1553
再見小時候
再見小時候 2021-01-01 00:28

I need to draw / doodle a line in UIImage like the picture above , I see a lot of tutorials doodle line on the UIView but not in the UIImage.

after the user

3条回答
  •  萌比男神i
    2021-01-01 01:05

    This may help you . Refer the link

    How do I draw on an image in Swift?

    1. Make an image graphics context. (Before iOS 10, you would do this by calling UIGraphicsBeginImageContextWithOptions. In iOS 10 there's another way, UIGraphicsImageRenderer, but you don't have to use it if you don't want to.)

    2. Draw (i.e. copy) the image into the context. (UIImage actually has draw... methods for this very purpose.)

    3. Draw your line into the context. (There are CGContext functions for this.)

    4. Extract the resulting image from the context. (For example, if you used UIGraphicsBeginImageContextWithOptions, you would use UIGraphicsGetImageFromCurrentImageContext.) Then close the context.

提交回复
热议问题