【发布时间】:2018-03-09 22:30:38
【问题描述】:
我正在尝试将背景与前景图像混合,其中前景图像是带有线条的透明图像。
我正在尝试这样做。
UIGraphicsBeginImageContext(CGSizeMake(320, 480));
CGContextRef context = UIGraphicsGetCurrentContext();
// create rect that fills screen
CGRect bounds = CGRectMake( 0,0, 320, 480);
// This is my bkgnd image
CGContextDrawImage(context, bounds, [UIImage imageNamed:@"bkgnd.jpg"].CGImage);
CGContextSetBlendMode(context, kCGBlendModeSourceIn);
// This is my image to blend in
CGContextDrawImage(context, bounds, [UIImage imageNamed:@"over.png"].CGImage);
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(outputImage, self, nil, nil);
// clean up drawing environment
//
UIGraphicsEndImageContext();
但似乎不起作用。
任何建议将不胜感激。
【问题讨论】:
-
技术说明:这是指“alpha-blending”(基于其中一个图像中的 alpha 通道合成两个图像),不是使用 Core Graphics “blend模式” - 如果这是您需要的,请再次搜索。实际上,Eric's answer 确实简要展示了一种混合模式的使用;您可以在那里替换不同的混合模式,并删除“alpha:0.8”参数。
标签: iphone alphablending