How to save a couple of images as one image to photo library in swift?

不问归期 提交于 2019-12-13 20:31:40

问题


There are three imageViews in first view controller (two donuts png and one Simpson image). Are there any solutions that I can capture these images as one image and save it to photo library? Thanks.


回答1:


Try this, passing in the base view that has all the subviews you need:

func createImage(from aView:UIView) -> UIImage {
    UIGraphicsBeginImageContextWithOptions(CGSize(width: aView.frame.width, height: aView.frame.height), true, 0)
    aView.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return image!
}


来源:https://stackoverflow.com/questions/51813876/how-to-save-a-couple-of-images-as-one-image-to-photo-library-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!