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 - 在 Objective-C 中,什么时候应该使用属性,什么时候应该使用实例变量?

iphone - 将屏幕从 Mac 流式传输到 iPhone

ios - UIKeyCommands 不工作

php - 如何从 PHP 中的 URL 上传图像

iphone - 如何查看被释放后正在接收消息的对象

iPhone分布: No profiles currently match

iphone - 如何在 UIPageViewController 中设置第一页

ios - UISearchController 在事件时不会从内存中释放

python - cv2.VideoWriter 的输出不正确。更快

c++ - opencv:在二值图像中拟合最小封闭椭圆