我想讀取一個像素在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讀入圖片 –