如何混合两个图像? [英] How to blend two images?

查看:177
本文介绍了如何混合两个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图中有两张图片,我需要混合这两张图片。但问题是无法完美融合。

I have two images in my view and i need to blend those two images. But the problem is unable to get perfect blend.

图像混合的代码

CGSize newSize = CGSizeMake(_backGroundImage.frame.size.width, _backGroundImage.frame.size.height);
UIGraphicsBeginImageContext( newSize );
[_backGroundImage.image drawInRect:CGRectMake(_backGroundImage.frame.origin.x,_backGroundImage.frame.origin.y,_backGroundImage.frame.size.width,_backGroundImage.frame.size.height) blendMode:kCGBlendModeNormal alpha:1.0];
[_foreGroundImage.image drawInRect:CGRectMake(_foreGroundImage.frame.origin.x,_foreGroundImage.frame.origin.y,_foreGroundImage.frame.size.width,_foreGroundImage.frame.size.height) blendMode:kCGBlendModeColor alpha:0.5];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[_resultImage setImage:newImage ];

我也试过不同的混合模式但无法获得结果。

I also tried with different blend mode but unable to get result.


请帮我解决这个问题

推荐答案

请更改此行

[_foreGroundImage.image drawInRect:CGRectMake(_foreGroundImage.frame.origin.x,_foreGroundImage.frame.origin.y,_foreGroundImage.frame.size.width,_foreGroundImage.frame.size.height) blendMode:kCGBlendModeLighten alpha:0.5];

这篇关于如何混合两个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆