UIImage *srcImage = [UIImage imageNamed:@"test_image"]; UIImage *dstImage = nil; UIImage *maskImage = [UIImage imageNamed:@"mask_image"]; CGImageRef m = maskImage.CGImage; CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(m), CGImageGetHeight(m), CGImageGetBitsPerComponent(m), CGImageGetBitsPerPixel(m), CGImageGetBytesPerRow(m), CGImageGetDataProvider(m), NULL, false); CGImageRef masked = CGImageCreateWithMask(srcImage.CGImage, mask); CGImageRelease(mask); UIImage *maskedImage = [UIImage imageWithCGImage:masked]; CGImageRelease(masked);
関連記事
この記事のSwift版を書きました。