4

我希望能够在图像边缘添加 alpha 渐变,使其“淡入”到下一张图像中。下图解释了我正在尝试做的事情。

示例图片

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

4

1 回答 1

-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];
于 2012-07-26T07:36:53.133 回答