Mani
Mani

Reputation: 1841

How to create own mask in ios

enter image description here

Duplicate

so don't negative my reputation.

My mask image is : enter image description here

My output is : enter image description here

- (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);
    CGImageRelease(mask);
    return [UIImage imageWithCGImage:masked];
}

So how to create my own mask image?

Thanks...

Upvotes: 8

Views: 1534

Answers (1)

Rok Jarc
Rok Jarc

Reputation: 18865

Try converting image to a grayscale image without alpha.

  • Save it as .jpg to remove alpha. Then you can save it back to png. This image should work already.

  • Convert it to greyscale (since color information is discarded in this kind of masking) by image->mode->greyscale.

enter image description here

Upvotes: 5

Related Questions