我对objective-c有点陌生,甚至对使用Quartz 2D编程也比较陌生,所以提前道歉!我有一种方法,我想从 UIImage 中删除一些特定颜色(不仅仅是一种)。
当我只应用一种颜色蒙版运行我的项目时,它的效果非常好。一旦我尝试堆叠它们,“whiteRef”就会出现 NULL。我什至尝试修改我的方法以获取颜色蒙版,然后简单地运行我的方法两次 - 输入不同颜色的蒙版 - 但仍然没有成功。
非常感谢您对此的任何帮助!
- (UIImage *)doctorTheImage:(UIImage *)originalImage
{
const float brownsMask[6] = {124, 255, 68, 222, 0, 165};
const float whiteMask[6] = {255, 255, 255, 255, 255, 255};
UIImageView *imageView = [[UIImageView alloc] initWithImage:originalImage];
UIGraphicsBeginImageContext(originalImage.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGImageRef brownRef = CGImageCreateWithMaskingColors(imageView.image.CGImage, brownsMask);
CGImageRef whiteRef = CGImageCreateWithMaskingColors(brownRef, whiteMask);
CGContextDrawImage (context, CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height), whiteRef);
CGImageRelease(brownRef);
CGImageRelease(whiteRef);
UIImage *doctoredImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[imageView release];
return doctoredImage;
}