私はobjective-cに少し慣れていないので、Quartz 2Dを使用したプログラミングはさらに新しいので、事前にお詫びします。UIImageから(1つだけではなく)いくつかの特定の色を削除したいメソッドがあります。
カラーマスクを1つだけ適用してプロジェクトを実行すると、美しく機能します。それらをスタックしようとすると、「whiteRef」はNULLになります。メソッドを変更してカラーマスクを取得してから、メソッドを2回実行して(異なるカラーマスクをフィードする)、それでもうまくいきませんでした。
これに関するどんな助けも大歓迎です!
- (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;
}