0

我正在使用CIFilter @"CIDarkenBlendMode". 它工作正常,除了一件事。无论图像大小如何,我都希望图像彼此完全对齐,但我无法实现这一点。我必须创建自己的过滤器吗?

这就是我得到的:

结果

这就是我要的:

我想要的是

我的合并代码:

-(void)mergeImagesWithCIImage:(UIImage*)image
{

    CIImage *topImage = [[CIImage alloc]initWithImage:image];
    CIImage *scaledImage = [self scaleImageWithCIImage:topImage];

    CIImage *backgroundImage = [[CIImage alloc]initWithImage:self.vImage.image];

    CIFilter *darkenFilter = [CIFilter filterWithName:@"CIDarkenBlendMode" keysAndValues:kCIInputImageKey,scaledImage,
                              @"inputBackgroundImage",backgroundImage,nil];

    CIImage *filterOutputImage = darkenFilter.outputImage;

    CIContext *ctx = [CIContext contextWithOptions:nil];
    CGImageRef createdImage = [ctx createCGImage:filterOutputImage fromRect:filterOutputImage.extent];

    UIImage *outputImage = [UIImage imageWithCGImage:createdImage];
    CGImageRelease(createdImage);
    createdImage = nil;

    self.vImage.image = outputImage;
}
4

1 回答 1

0

而不是使用 CIFilter 我使用:

[_image drawInRect:CGRectMake(centerX,centerY,_image.size.width,_image.size.height) blendMode:kCGBlendModeDarken alpha:0.8];

并将图像居中。

于 2013-09-27T08:58:58.733 回答