GPUImage: How to blend two images of different size while maintaining original aspect ratio for both images?

StackOverflow https://stackoverflow.com//questions/20002697

  •  20-12-2019
  •  | 
  •  

Question

I use the following code to blend two images. It works, but topImage gets resized to match the aspect ratio of baseImage. How can I maintain the original size and aspect ratio for both baseImage and topImage?

 GPUImageMultiplyBlendFilter *overlayBlendFilter = [[GPUImageMultiplyBlendFilter alloc] init];
    GPUImagePicture *pic1 = [[GPUImagePicture alloc] initWithImage:baseImage];
    GPUImagePicture *pic2 = [[GPUImagePicture alloc] initWithImage:topImage];

    [pic1 addTarget:overlayBlendFilter];
    [pic1 processImage];
    [pic2 addTarget:overlayBlendFilter];
    [pic2 processImage];

    UIImage *blendedImage = [overlayBlendFilter imageByFilteringImage:topImage];

    [imageView setImage:blendedImage];
Was it helpful?

Solution

I've managed to solve this my self. I dont know if this is the optimal solution but what i did is resize topimage, before the blend occurs, by adding transparent space to it in order to get dimensions with the same aspect ratio as the baseimage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top