Iphone 使图像黑白相间?

Iphone 使图像黑白相间?,iphone,colors,quartz-graphics,quartz-2d,Iphone,Colors,Quartz Graphics,Quartz 2d,我还有一个quartz 2d(iphone)问题: 如何将ImageView的所有颜色更改为黑色和白色,而只保留红色 DD 这是我在其他论坛上发现的东西,它似乎很有效 +1对你来说,这很有效,甚至我用了这段代码…谢谢你,伙计 UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage]; this image we get from UIImagePickerController C

我还有一个quartz 2d(iphone)问题:

如何将ImageView的所有颜色更改为黑色和白色,而只保留红色

DD


这是我在其他论坛上发现的东西,它似乎很有效

+1对你来说,这很有效,甚至我用了这段代码…谢谢你,伙计
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];  this image we get from UIImagePickerController

    CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray();
    CGContextRef context = CGBitmapContextCreate(nil, originalImage.size.width, originalImage.size.height, 8, originalImage.size.width, colorSapce, kCGImageAlphaNone);
    CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
    CGContextSetShouldAntialias(context, NO);
    CGContextDrawImage(context, CGRectMake(0, 0, originalImage.size.width, originalImage.size.height), [originalImage CGImage]);

    CGImageRef bwImage = CGBitmapContextCreateImage(context);
    CGContextRelease(context);
    CGColorSpaceRelease(colorSapce);

    UIImage *resultImage = [UIImage imageWithCGImage:bwImage]; // This is result B/W image.
    CGImageRelease(bwImage);