Pregunta

I am Working on Photo Editing App and I have to merge two Images one Over another like this.

enter image description here

I have implemented the following code to do so:
Here imgedit is the background image and
imgEdit is the UIImageView containing imgedit.

        UIImage *tempImg = [UIImage imageNamed:[NSString stringWithFormat:@"borderImg"]];
        CIImage *inputBackgroundImage = [[CIImage alloc] initWithImage:imgedit];
        CIImage *inputImage = [[CIImage alloc]initWithImage:tempImg] ;

        CIFilter *filter = [CIFilter filterWithName:@"CISourceOverCompositing"];
        [filter setDefaults];
        [filter setValue:inputImage forKey:@"inputImage"];
        [filter setValue:inputBackgroundImage forKey:@"inputBackgroundImage"];

        CIImage *outputImage1 = [filter valueForKey:@"outputImage"];
        CIContext *context = [CIContext contextWithOptions:nil];
        imgEdit.image = [UIImage imageWithCGImage:[context createCGImage:outputImage1 fromRect:outputImage1.extent]];

But the outputImage I am getting after implementing above code is:
enter image description here

I have also tried to resize the input white frame image, by using following code:

        tempImg=[tempImg resizedImageToSize:CGSizeMake(imgEdit.image.size.width,imgEdit.image.size.height)];  

By using above code image get resized properly but But that is also not working.

Please help me out from here.
Your valuable help will be highly appreciated.
Thankyou in advance.

¿Fue útil?

Solución

A better way to resize is as follows:

inputImage = [inputImage imageByApplyingTransform:CGAffineTransformMakeScale(inputBackgroundImage.extent.size.width/inputImage.extent.size.with, inputBackgroundImage.extent.size.height/inputImage.extent.size.height)];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top