iphone - 平均多个 UIImages

标签 iphone ios uiimage average blending

我一直在寻找这个答案。但是我没能找到它。

我想平均 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/

相关文章:

iphone - UIImageView 仅在我调用 initWithImage 时显示

ios - 以编程方式关闭 iOS 屏幕

ios - 如何通过 "photos-redirect:"URL 方案在照片应用 iOS 中显示最后保存的照片?

ios - UITextfield 作为 float 通过 segue 传递到 UILabel

ios - 如何获取具有所有(递归)子项的 PFUser 对象

iphone - 将 PDF 加载到 UIImage 或 UIImageView 中?

iphone - UITableView - 扩展单元格

iphone - iOS 自定义单元格不起作用

ios - 迁移核心数据存储时的错误消息

iOS UIImage : set image orientation without rotating the image itself