Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mask image by pattern

How to mask/crop a picture using the pattern like the image in UIImageView? Can any one help me with refrences?

enter image description here

like image 933
Dev_iOS Avatar asked Mar 18 '26 17:03

Dev_iOS


1 Answers

Pass two images to the below function. 1) Image to be mask and 2) your mask pattern Image.

- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

        CGImageRef maskRef = maskImage.CGImage; 

        CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
            CGImageGetHeight(maskRef),
            CGImageGetBitsPerComponent(maskRef),
            CGImageGetBitsPerPixel(maskRef),
            CGImageGetBytesPerRow(maskRef),
            CGImageGetDataProvider(maskRef), NULL, false);

        CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
        return [UIImage imageWithCGImage:masked];

    }

You can refer the full tutorial here.

If you want to clip image by passing some path then have a look at this SO Answer.

Hope this will solve your problem.

like image 183
Moin Ahmed Avatar answered Mar 20 '26 08:03

Moin Ahmed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!