将UIImage与alpha值混合

时间:2012-09-21 09:10:56

标签: iphone objective-c ios cocoa-touch uiimage

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

1 个答案:

答案 0 :(得分: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