Alpha mask gradient on uiimageview

I would like to add an alpha gradient to the edge of the image so that it โ€œfadesโ€ to the next image. The figure below explains what I'm trying to do.

Example Picture

Any idea on how to do this? I donโ€™t have much experience with the graphics context, so here I ask for help.

+4
source share
1 answer

You can check this code and post the result.

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]; 
-1
source

All Articles