将多层 CALayer 图像保存到库中?
Saving multi layer CALayer image to Library?
所以我得到了一个视图,其中有一个层和一些子层,这些子层具有 compositingFilter 设置和混合模式以查看层。我想将所有子图层保存到照片库中的一张图像中。视图中的一切看起来都不错,但是当我保存 CALayer 时,通过使用 UIGraphicsContext 将其转换为 UIImage 并使用 UIImageWriteToSavedPhotosAlbum,我只保存了一层。
有谁知道如何将 CALayer 中的多个子层转换为 UIImage 吗?
和你有同样的问题,我通过imageView.layer.addSublayer(newLayer)
向UIImageView的CALayer添加了很多子层。
按照其他人的指示解决了它。
希望我的代码能给出任何想法。
@IBAction func saveArtwork(_ sender: Any) {
UIGraphicsBeginImageContext(self.imageView.bounds.size)
// The code below may solve your problem
imageView.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let activity = UIActivityViewController(activityItems: [image!], applicationActivities: nil)
present(activity, animated: true, completion: nil)
}
所以我得到了一个视图,其中有一个层和一些子层,这些子层具有 compositingFilter 设置和混合模式以查看层。我想将所有子图层保存到照片库中的一张图像中。视图中的一切看起来都不错,但是当我保存 CALayer 时,通过使用 UIGraphicsContext 将其转换为 UIImage 并使用 UIImageWriteToSavedPhotosAlbum,我只保存了一层。
有谁知道如何将 CALayer 中的多个子层转换为 UIImage 吗?
和你有同样的问题,我通过imageView.layer.addSublayer(newLayer)
向UIImageView的CALayer添加了很多子层。
按照其他人的指示解决了它。 希望我的代码能给出任何想法。
@IBAction func saveArtwork(_ sender: Any) {
UIGraphicsBeginImageContext(self.imageView.bounds.size)
// The code below may solve your problem
imageView.layer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
let activity = UIActivityViewController(activityItems: [image!], applicationActivities: nil)
present(activity, animated: true, completion: nil)
}