How to create own mask in ios

核能气质少年 提交于 2019-12-09 11:44:46

问题


Duplicate

so don't negative my reputation.

My mask image is :

My output is :

- (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...


回答1:


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.



来源:https://stackoverflow.com/questions/10992290/how-to-create-own-mask-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!