8

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

Community
  • 1
  • 1
Mani
  • 1,841
  • 15
  • 29
  • 2
    Mask image should be grayscale with no alpha channel. – Rok Jarc Jun 12 '12 at 07:37
  • Please tell me , how to edit this image with photoshop.. – Mani Jun 12 '12 at 07:38
  • 2
    First save it as .jpg to remove alpha. Then you can save it back to png. This image should work already. But you can also convert it to greyscale (since color information is discarded in this kind of masking) by image->mode->greyscale. – Rok Jarc Jun 12 '12 at 07:45
  • 1
    rokjarc :) thanks now its working great. Thanks friend... thanks alot. – Mani Jun 12 '12 at 07:51

1 Answers1

5

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

Rok Jarc
  • 18,765
  • 9
  • 69
  • 124