Reputation: 1841
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...
Upvotes: 8
Views: 1534
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.
Upvotes: 5