2012-09-21 84 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

與上面相同的代碼。 –