Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何更改结果以打印目标C中的RGB像素值_Ios_Iphone - Fatal编程技术网

Ios 如何更改结果以打印目标C中的RGB像素值

Ios 如何更改结果以打印目标C中的RGB像素值,ios,iphone,Ios,Iphone,我有这个代码,我希望它返回每个像素的RGB颜色值,而不是亮度。目前,它将每个像素的亮度打印到命令行上,我希望将其更改为打印每个像素的RGB值。我对Objective-C相当陌生,因此非常感谢您的帮助和解释:) //1。获取图像的像素 CGImageRef inputCGImage=[image CGImage]; NSU整数宽度=CGImageGetWidth(inputCGImage); NSU整数高度=CGImageGetHeight(inputCGImage); NSU整数字节/像素=4

我有这个代码,我希望它返回每个像素的RGB颜色值,而不是亮度。目前,它将每个像素的亮度打印到命令行上,我希望将其更改为打印每个像素的RGB值。我对Objective-C相当陌生,因此非常感谢您的帮助和解释:)

//1。获取图像的像素
CGImageRef inputCGImage=[image CGImage];
NSU整数宽度=CGImageGetWidth(inputCGImage);
NSU整数高度=CGImageGetHeight(inputCGImage);
NSU整数字节/像素=4;
NSUInteger bytesPerRow=bytesPerPixel*宽度;
NSU整数比特分量=8;
UInt32*像素;
像素=(UInt32*)calloc(高度*宽度,大小(UInt32));
CGColorSpaceRef colorSpace=CGColorSpaceCreateDeviceRGB();
CGContextRef context=CGBitmapContextCreate(像素、宽度、高度、,
bitsPerComponent、bytesPerRow、颜色空间、,
KCGIMAGEAlphaPremultipledLast | kCGBitmapByteOrder32Big);
CGContextDrawImage(上下文,CGRectMake(0,0,宽度,高度),inputCGImage);
CGCOLORSPACTERELEASE(色彩空间);
CGContextRelease(上下文);
#定义Mask8(x)((x)和0xFF)
#定义R(x)(Mask8(x))
#定义G(x)(Mask8(x>>8))
#定义B(x)(Mask8(x>>16))
// 2. 迭代并记录!
NSLog(@“图像亮度:”);
UInt32*当前像素=像素;
对于(整数j=0;j
只需更改此行:

printf("%3.0f ", (R(color)+G(color)+B(color))/3.0);


非常感谢你!!
printf("%3.0f ", (R(color)+G(color)+B(color))/3.0);
printf("(r=%3.0f, g=%3.0f, b=%3.0f) ", R(color), G(color), B(color));