CIFilter: Blend different size images
Asked Answered
D

1

10

I'm using CISourceOverCompositing to blend two images. It works ok with same size images with this code:

CIFIlter *filter1 = [CIFilter filterWithName: @"CISourceOverCompositing"];
[filter1 setDefaults];
[filter1 setValue: imageForeground forKey: @"inputImage"];
[filter1 setValue: imageBackground forKey: @"inputBackgroundImage"];
CIImage *outputImage = [filter1 outputImage];

Now I have different image sizes, for example:

imageForeground: 50px x 50px

imageBackground: 500px x 500px

The previous code set the imageForeground at (0, 0) position of the outputImage.

How can I blend these images positioning the imageForeground, for example, at (100, 100) position?

Thanks in advance!

Detonator answered 4/11, 2013 at 21:14 Comment(0)
S
17

It's pretty easy - just transform the input image like so:

[filter1 setValue:[imageForeground imageByApplyingTransform:CGAffineTransformMakeTranslation(100, 100)] forKey:kCIInputImageKey]
Skite answered 4/11, 2013 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.