【发布时间】:2016-03-02 23:27:02
【问题描述】:
我正在创建一个应用程序,用户可以在其中从一组图像(多个)中进行选择,并将所选图像添加到所选背景。然后他们应该能够保存图像,因此我需要帮助将所有图像合并为一张以进行保存。
ViewController 有一个大的 UIImageView 作为背景。当用户选择要添加的图片时,该图片会作为子视图添加到 UIImageView 中。
//chosenImage is a UIImageView with an chosen image
backgroundImageView.addSubView(chosenImage)
我需要将图像保存为带有叠加图像的 backgroundView 的大小。
我怎样才能做到这一点?
我四处搜索,但只找到了 Obj-C 的答案和一些不起作用的答案。
对于那些寻找相同答案的人来说,这就是您在按下按钮时保存图像的方法:
@IBAction func saveImage(sender: AnyObject) {
let snapShot:UIView = backgroundImage.snapshotViewAfterScreenUpdates(true)
UIGraphicsBeginImageContext(backgroundImage.bounds.size)
snapShot.drawViewHierarchyInRect(backgroundImage.bounds, afterScreenUpdates: true)
let image:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
【问题讨论】:
标签: ios swift uiimageview uiimage