iPhone,如何将一个图像叠加到另一个图像上以创建要保存的新图像? (水印) [英] iPhone, how does one overlay one image onto another to create a new image to save? (watermark)
问题描述
基本上我想拍摄用户从照片库中选择的图像,然后应用水印,右下角有一个应用程序名称的三角形。我已经在photoshop中使用透明层制作了第二张图像。
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.
我尝试了一个功能,我记不起它的确切名称,但它涉及CGIImages和蒙版。这组合了两个图像,但作为一个遮罩,使得图像在透明层所在的位置更暗,图像本身没有合并,只是掩盖了。
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.
如何我得到水印图像与另一个图像合并,制作UIImage,而不在屏幕上显示图像?
How would I get the watermark image to merge with another image, to make a UIImage, without displaying the images on the screen?
谢谢。
推荐答案
这很简单:
UIImage *backgroundImage = [UIImage imageNamed:@"image.png"];
UIImage *watermarkImage = [UIImage imageNamed:@"watermark.png"];
UIGraphicsBeginImageContext(backgroundImage.size);
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
[watermarkImage drawInRect:CGRectMake(backgroundImage.size.width - watermarkImage.size.width, backgroundImage.size.height - watermarkImage.size.height, watermarkImage.size.width, watermarkImage.size.height)];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
如果您希望背景和水印的大小相同,请使用此代码
If you want the background and watermark to be of the same size then use this code
...
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
[watermarkImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
...
这篇关于iPhone,如何将一个图像叠加到另一个图像上以创建要保存的新图像? (水印)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!