结合两个透明的UIImages?

时间:2014-09-06 03:37:16

标签: ios uiimage cgcontext

我正在尝试使用以下代码组合两个透明的UIImages:

UIImage* image1;
UIImage* image2;

UIGraphicsBeginImageContext( image1.size );

[ image1 drawInRect: CGRectMake( 0, 0, image1.size.width, image1.size.height ) ];
[ image2 drawInRect: CGRectMake( 0, 0, image2.size.width, image2.size.height ) ];

UIImage* combinedImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

正确组合了alpha,但未保留颜色。因为CGContext最初具有黑色(即使具有0 alpha),所以在image1或image2透明的情况下,所得到的UIImage向黑色移动。怎么解决这个问题?我尝试了不同的混合模式但没有成功。

0 个答案:

没有答案
相关问题