0
我知道还有其他几种方法可以做到这一点;我不想输入任何我不需要的东西。如果有人可以用他的代码来帮助我,那会很棒。如何使用此代码为图像添加水印?
目前,它只保存没有水印图像的原始图像。
extension UIImage {
class func imageWithWatermark(image1: UIImageView, image2: UIImageView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(image1.bounds.size, false, 0.0)
image2.layer.renderInContext(UIGraphicsGetCurrentContext()!)
image1.layer.renderInContext(UIGraphicsGetCurrentContext()!)
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return img
}
}
func addWatermark() {
let newImage = UIImage.imageWithWatermark(imageView, image2: watermarkImageView)
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil)
}
编辑:我已经有水印出现在保存的图像。
我不得不切换层的顺序:
image1.layer.renderInContext(UIGraphicsGetCurrentContext()!)
image2.layer.renderInContext(UIGraphicsGetCurrentContext()!)
但是,它没有出现在正确的place.It似乎总是出现在图像的中心。
所以你要简单地把一些文字图像? –
你看看http://stackoverflow.com/questions/6992830/how-to-write-text-on-image-in-objective-c-iphone? –
对不起,没有图片。我想要一个图像在另一个图像上面。 – bkwebhero