在uiimageview上的Alpha蒙版渐变

时间:2012-07-26 05:59:07

标签: objective-c uiimageview quartz-graphics alpha

我希望能够在图像的边缘添加一个alpha渐变,使其“淡入”下一个图像。下图说明了我要做的事情。

Example Picture

有关如何做到这一点的任何想法?我对图形上下文没有太多经验,这就是我在这里寻求帮助的原因。

1 个答案:

答案 0 :(得分:-1)

您可以查看此代码并发布结果。

UIImage* first = [[UIImage alloc]initWithContentsOfFile:@"firstImagePath"];
UIImage* second = [[UIImage alloc]initWithContentsOfFile:@"secondImagePath"];
CGSize sizeToSet;
int mergeArea = 200;
sizeToSet.width = first.size.width + second.size.width - mergeArea;
sizeToSet.height = first.size.height;

UIGraphicsBeginImageContext(sizeToSet);

[first drawAtPoint:CGPointMake(0, 0)];
[second drawAtPoint:CGPointMake(first.size.width - mergeArea, 0) blendMode:kCGBlendModeLuminosity alpha:1.0f];

UIImageView* imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
[imageView setCenter:self.view.center];
[imageView setImage:UIGraphicsGetImageFromCurrentImageContext()];

UIGraphicsEndImageContext();

[[self view]addSubview:imageView];

[imageView release];
[first release];
[second release];