开发者

How erase part of UIImage with an other UIImage

开发者 https://www.devze.com 2023-02-01 22:28 出处:网络
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

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

How erase part of UIImage with an other UIImage

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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消