2012-09-21 42 views
0

如何通过仅更改一个图像的alfa来混合两个图像,以便上面的图像稍微透明,并且上图将在背景图上绘制时显示。使用alpha值混合UIImage

+0

可能的复制http://stackoverflow.com/questions/1309757/blend-two-uiimages – waldrumpus

回答

0

你可以做到这一点通过ImageView的alpha属性

imageView.alpha = 0.0f; 

详细代码:

UIImage *bottomImage = [UIImage imageNamed:@"bottomImage.png"]; 
    UIImage *topImage = [UIImage imageNamed:@"topImage.png"]; 

    CGSize newSize = CGSizeMake(width, height); 
    UIGraphicsBeginImageContext(newSize); 

    // Use existing opacity as is 
    [bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; 
    // Apply supplied opacity 
    [topImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8]; 

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); 

    UIGraphicsEndImageContext(); 

看到更多细节的here

+0

我有上面的代码,但是当我改变alpha值背景图像al pha也会改变。 –

+0

可以请你分享你的代码? –

+0

与上面相同的代码。 –