views:

26

answers:

0

Hi guys

I am trying to mask the image with another image but i did not success. I am using the following code.

-(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];
}

But i success to provide the same shape to the image but return image like the negative image of the image in the shape of the mask image.