iphone - 在 iPhone SDK 中将图像转换为黑白、棕褐色、灰度等

标签 iphone objective-c image-processing uiimage

我在谷歌上搜索是否找到了一些可以给图像添加效果的东西,比如黑白SepiagrayScale等。我找到了一个用于将图像转换为 Sepia 的有用链接,但没有任何内容可以将其转换为黑白或灰度。

这是链接http://groups.google.com/group/iphonesdkdevelopment/browse_thread/thread/b987b02deec08b9f

浏览完代码后,我知道我们需要为此更改 RBG,但如何获取 B&WgrayScale 的 RBG。此类效果的 RBG 比率是多少。

任何帮助将不胜感激。

提前致谢

最佳答案

您可以通过以下方式获取黑白图像

-(UIImage *)convertOriginalImageToBWImage:(UIImage *)originalImage
{
UIImage *newImage;

CGColorSpaceRef colorSapce = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(nil, originalImage.size.width * originalImage.scale, originalImage.size.height * originalImage.scale, 8, originalImage.size.width * originalImage.scale, 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];
CGImageRelease(bwImage);

UIGraphicsBeginImageContextWithOptions(originalImage.size, NO, originalImage.scale);
[resultImage drawInRect:CGRectMake(0.0, 0.0, originalImage.size.width, originalImage.size.height)];
newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


return newImage;
}

关于iphone - 在 iPhone SDK 中将图像转换为黑白、棕褐色、灰度等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8613290/

相关文章:

iphone - 使用 CALayer 绘制虚线

ios - 在 Objective-C 中将自定义类注入(inject)子类继承树

objective-c - 在 Xcode 中为 iPad 指定图像,例如为 iPhone 4 指定 @2x

objective-c - 如何将数据放入文本字​​段进行编辑?

matlab - 霍夫变换以检测和删除线

python-3.x - 如何找到轮廓的坐标并进行裁剪?

iphone - 如何让通用应用程序同时显示在应用程序商店的两个部分中

iphone - 在 iOS 中使用街道地址

python - 如何使用python从视频中提取幻灯片

html - iPhone 未显示 HTML 选择 iOS 12.1.4 的完整选项