如何在iPhone中将一个图像叠加到另一个图像上

时间:2012-08-21 08:43:54

标签: iphone camera uiimage overlay

在我的应用程序中,我有一个透明图像,现在当用户从照片库中选择一个图像时,该图像必须显示在透明图像上并制作为一个uiiimage,以便用户可以邮寄或与之共享。我使用了以下代码,但图像在透明图像上不正确

UIImage *backgroundImage = [UIImage imageNamed:@"iPhoneOverLay.png"];

UIGraphicsBeginImageContext(backgroundImage.size);
[backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
[testImage drawInRect:CGRectMake(backgroundImage.size.width - testImage.size.width, backgroundImage.size.height - testImage.size.height, testImage.size.width, testImage.size.height)];
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

此处testImage从Photo Library中选择或从相机中选取

1 个答案:

答案 0 :(得分:0)

您以错误的顺序绘制2张图像。透明度是一种让事物发光的属性,它已被以前绘制。因此,您必须先绘制(不透明)照片,然后再绘制(透明)覆盖图。

相关问题