iPhone,如何将一张图像叠加到另一张图像上以创建要保存的新图像? (水印)
基本上,我想拍摄用户从照片库中选择的图像,然后应用水印,即右下角的三角形,上面有应用程序名称。我已经在 Photoshop 中用透明层制作了第二张图像。
我尝试了一个函数,我不记得它的确切名称,但它涉及 CGIImages 和蒙版。这将两个图像结合在一起,但作为遮罩,这使得透明层所在的图像变暗,并且图像本身并未合并,只是被遮罩了。
如何将水印图像与另一个图像合并以制作 UIImage,而不在屏幕上显示图像?
谢谢。
Basically I want to take an image that the user chooses from their photo library and then apply a watermark, a triangle in the lower right that has the app name on it. I have the second image already made with a transparent layer in photoshop.
I tried a function, which I can't remember the exact name, but it involved CGIImages and masks. This combines the two images, but as a mask, which made the image darker where the transparent layer was and the images were not merged per se, just masked.
How would I get the watermark image to merge with another image, to make a UIImage, without displaying the images on the screen?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这很简单:
如果您希望背景和水印具有相同的大小,则使用此代码
It's pretty easy:
If you want the background and watermark to be of the same size then use this code
omz 提供的解决方案也适用于 Swift,如下所示:
The solution provided by omz also works in Swift, like so:
SWIFT 4
使用 UIImageView 的结果进行测试。
SWIFT 4
Use result to UIImageView, tested.
您可以使用这种方法,它非常动态,您可以指定第二个图像的起始位置和图像的总大小。
You can use this method, which is very dynamic and you can specify the starting position of the second image and total size of the image.
SWIFT 5 功能:
SWIFT 5 Function: