How to combine drawn pixels in a UIView with the i

2019-08-27 03:05发布

问题:

I am wondering how to combine drawn pixels in a UIView with the image in a UIImageView and save it as a new image? I have no clue how to go about this.

If anyone could point me in the right direction, I would love it.

Thank you!

回答1:

Check out Quartz 2D. Specifically, CGContextDrawImage() can be used to load an image, draw whatever you want on this context, and then you can CGBitmapContextCreateImage() to create a CGImageRef from which you can create an image with UIImage's imageWithCGImage. Finally, you use UIImagePngRepresentation() or UIImageJPEGRepresentation() to get a NSData that you can then use writeToFile with.