• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)

用户头像
it1352
帮助291

问题说明

基本上,我想拍摄用户从他们的照片库中选择的图像,然后应用水印,右下角有一个三角形,上面有应用程序名称.我已经在 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?

谢谢.

正确答案

#1

很简单:

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)];
...

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tangckhbk
系列文章
更多 icon
同类精品
更多 icon
继续加载