iphone - 将图像设为黑白?

标签 iphone colors quartz-graphics quartz-2d

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

如何将 ImageView 的所有颜色更改为黑白并仅保留红色???

DD

最佳答案

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);

这是我在其他论坛上找到的东西,它似乎有效!!!

关于iphone - 将图像设为黑白?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3521261/

相关文章:

.net - 预览 .NET 颜色

cocoa-touch - CGContextDrawAngleGradient?

objective-c - uiimageview 上的 Alpha 蒙版渐变

iphone - MonoTouch - 设置 bundle - iPhone

iphone - 纬度/经度坐标到屏幕位置的奇怪转换

opengl - GLSL 1.5 和 OpenGL 3.3 : Passing color to vertex shader seems to fail

c# - TreeView 绘制故障

ios - 在 iOS 中进行复制拟合的最佳方法?

iphone - 警告 : Ignoring call to [UIPanGestureRecognizer setTranslation:inView:]

iphone - iPhone应用程序在首次运行/安装(apns?)时崩溃,但在…日志附加后还可以