CIFilter: mix images of different sizes

I use CISourceOverCompositing to mix two images. It works fine with images of the same size 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 sets the value of imageForeground to the (0, 0) position of outputImage.

How can I mix these images by positioning the Foreground image, for example, at (100, 100)?

Thanks in advance!

+6
source share
1 answer

It's pretty simple - just convert the input image like this:

 [filter1 setValue:[imageForeground imageByApplyingTransform:CGAffineTransformMakeTranslation(100, 100)] forKey:kCIInputImageKey] 
+12
source

Source: https://habr.com/ru/post/957381/


All Articles