我正在尝试读取 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]
但结果是一样的。
我没有收到错误消息或警告,但我认为加载图片时有问题?请帮助我,我做错了什么?有没有更好的方法来读取像素颜色数据?