我创建使用ARGB和kCGImageAlphaPremultipliedFirst格式。为什么像素颜色存储为(255数据)?
UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
[image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)];
// more code - not relevant - removed for debugging
image = UIGraphicsGetImageFromCurrentImageContext(); // the image is now ARGB
UIGraphicsEndImageContext();
然后我尝试(从这里米纳斯Petterson的使用代码:Get Pixel color of UIImage)找到一个像素的颜色的图像。 但因为图像是现在ARGB格式,我不得不修改了代码与此:
alpha = data[pixelInfo];
red = data[(pixelInfo + 1)];
green = data[pixelInfo + 2];
blue = data[pixelInfo + 3];
然而,这没有奏效。
的问题是,(例如)红色像素,在RGBA将表示为(实际上255 0 0 255,但为了简单起见我用0至1的值),在图像是表示为和不(如我想) 。 任何想法为什么?难道我做错了什么?
PS。我必须使用的代码看起来像它必须是这样的:
alpha = 255-data[pixelInfo];
red = 255-data[(pixelInfo + 1)];
green = 255-data[pixelInfo + 2];
blue = 255-data[pixelInfo + 3];
A(笨)的解决方案是隐蔽的使用该命令图像RGBA:图像= [UIImage的imageWithData:UIImagePNGRepresentation(图像)];但我想至少有10个更好的方法来解决我的问题! – Gik