简体   繁体   中英

Core Image Filter CISourceOverCompositing not working Properly

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

在此输入图像描述

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:
在此输入图像描述

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.

调整大小的更好方法如下:

inputImage = [inputImage imageByApplyingTransform:CGAffineTransformMakeScale(inputBackgroundImage.extent.size.width/inputImage.extent.size.with, inputBackgroundImage.extent.size.height/inputImage.extent.size.height)];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM