我一直在寻找这个答案。但是我没能找到它。
我想平均 30 个 UIimages 的像素。为此,我想使用 Quartz2D 而不是遍历所有图像的所有像素。我突然想到,为了一起绘制 30 张图像,我应该将每张图像的 Alpha channel 调整为 1/30。然后,在一个叠加另一个之后,我会得到想要的效果。
所需的公式应为:Dest Px = (img[0].px+....img[29].px)/30
我曾尝试使用 imageContext 并将图像混合在一起来实现它,但没有成功:
UIGraphicsBeginImageContext(CGSizeMake(sz.width, sz.height));
for (int i=0; i<30; i++) {
UIImage* img = [self.delegate requestImage:self at:i];
CGPoint coord = [self.delegate requestTranslation:self at:i];
[img drawAtPoint:coord blendMode:kCGBlendModeNormal alpha:1/30];
}
UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
我怎样才能得到许多 UIimages 的平均图像? 我也尝试过添加具有许多子图层的图像,但我也得到了褪色的图像。
谢谢!
最佳答案
尝试更改以下内容:
[img drawAtPoint:coord blendMode:kCGBlendModeNormal alpha:1/30];
到
[img drawAtPoint:coord blendMode:kCGBlendModeNormal alpha:1.0/30.0];
1/30(使用整数值)== 0,因此您将绘制完全透明的图像。通过添加 .0
,您表明您需要一个 CGFloat
。
关于iphone - 平均多个 UIImages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7948401/