2014-12-31 22 views
0

我試圖創建一個NSBitmapImageRep對象,每個樣本32位和一個alpha通道(總共128位/像素)。試圖創建一個32 bpc NSBitmapImageRep,遇到錯誤

我的代碼看起來是這樣的:

let renderSize = NSSize(width: 640, height: 360) 
let bitmapRep = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: Int(renderSize.width), pixelsHigh: Int(renderSize.height), bitsPerSample: 32, samplesPerPixel: 4, hasAlpha: true, isPlanar: false, colorSpaceName: NSCalibratedRGBColorSpace, bytesPerRow: 16 * Int(renderSize.width), bitsPerPixel: 128) 
println(bitmapRep) //prints "nil" 
println(16 * Int(renderSize.width)) //prints 10240 
println() 

//So what does a 'valid' 32bpc TIFF file with an alpha channel look like? 
let imgFile = NSImage(named: "32grad") //http://i.peterwunder.de/32grad.tif 
let imgRep = imgFile?.representations[0] as NSBitmapImageRep 
println(imgRep.bitsPerSample) //prints 32 
println(imgRep.bitsPerPixel) //prints 128 
println(imgRep.samplesPerPixel) //prints 4 
println(imgRep.bytesPerRow) //prints 10240 
println(imgRep.bytesPerRow/Int(imgFile!.size.width)) //prints 16 

這出現在控制檯執行第2行後:

2014-12-31 04:49:16.639 PixelTestBed [4413:2775703]不一致設置值創建NSBitmapImageRep

這是怎麼回事?爲什麼我無法手動創建具有與TIFF圖像具有完全相同值的NSBitmapImageRep?

順便說一句,我不能在這裏上傳圖像,因爲imgur會屠殺圖像的質量。畢竟,它是一個3,7 MB 32bp的TIFF,帶有alpha通道。

回答

1

您正在試圖分配32個bitsPerSample其是列於文檔中指定的範圍內的:

BPS

應用於的 單個組件來指定一個像素的比特數數據。假定所有組件都具有每個採樣相同的位數。 bps的應該是這些值中的一個:1,2,4,8,12,或16

NSBitmapImageRep Class Reference

+0

想我得湊合每個採樣16個比特。噓,蘋果。 –