我想读取一个像素在tif图像中的颜色值,但我无法找到正确的方法来做到这一点。我使用OSX和我的做法如下:试图获得像素的颜色值
NSImage *picture = [[NSImage alloc] initWithContentsOfFile:@"bais2.tif"]; //file is located in resoureces folder.
NSBitmapImageRep *imageRep = [[picture representations] objectAtIndex:0];
NSColor* color = [imageRep colorAtX:10 y:10];
NSLog(@"%f %f, %f", [color redComponent], [color blueComponent], [color greenComponent]);
的问题是,由于某些原因的NSLog的记录值始终为0.0000000 ....
我也曾尝试使用方法:
NSBitmapImageRep* imageRep = [[NSBitmapImageRep alloc] initWithData:[picture TIFFRepresentation]];
而不是[[picture representations] objectAtIndex:0]
但结果是一样的。
我没有收到错误消息或警告,但我认为在加载图片时出现错误? 请帮助我,我做错了什么?有没有更好的方法来读取像素颜色数据?
nslog图片并告诉它是否打印? –
不......我在登录图像时得到空白...... *困惑*。 – Nisse
所以这里是问题所在,你无法将bais2.tif读入图片 –