klefevre
klefevre

Reputation: 8735

How erase part of UIImage with an other UIImage

I posted that question and I have not yet found a solution.
I was wondering if there is a way to use an UIImage to delete a part of an other UIImage alt text

I would use an UIImage to 'mask' this ugly black background to let a transparency color.
Maybe with CGContextAddPath but I don't know how to use it...

Regards,
KL94

Upvotes: 1

Views: 836

Answers (1)

Minsu
Minsu

Reputation: 81

Simple solution

- (UIImage*)eraseImage:(UIImage*)img1 WithImage:(UIImage*)img2
{
    UIGraphicsBeginImageContext(img1.size);
    [img1 drawInRect:CGRectMake(0, 0, img1.size.width, img1.size.height)];
    [img2 drawInRect:CGRectMake(0, 0, img2.size.width, img2.size.height) blendMode:kCGBlendModeDestinationIn alpha:1.0];
    UIImage* result_img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return result_img;
}

But you better save image as transparent.(Like PNG)

Upvotes: 1

Related Questions