2013-05-28 396 views
0

我在找CVPixelBufferCreateWithBytes()函數的示例iOSCVPixelBufferCreateWithBytes快速創建CIImage

我有一個32BGRA像素的C型陣列,我期待快速創建一個CIImage而不復制它們。我的解決方案將暫時涉及int* -> CVPixelBuffer -> CIImage.

如果有更好的方法,請讓我知道。謝謝!

回答

0

如何:

+ (CIImage *)imageWithBitmapData:(NSData *)d bytesPerRow:(size_t)bpr size:(CGSize)size format:(CIFormat)f colorSpace:(CGColorSpaceRef)cs 

(全網址:http://developer.apple.com/library/ios/Documentation/GraphicsImaging/Reference/QuartzCoreFramework/Classes/CIImage_Class/Reference/Reference.html#//apple_ref/occ/clm/CIImage/imageWithBitmapData:bytesPerRow:size:format:colorSpace :)

看來,這個方法可能做的伎倆!我不確定你的C風格數組是什麼數據格式,但是,慢慢地繼續這個。它看起來像你的數據需要在這種格式(根據文檔)

kCIFormatARGB8 
A 32 bit-per-pixel, fixed-point pixel format. 
+0

這看起來很有用。但是,如何獲得int *到NSData *?似乎沒有可以發送的init類方法。是NSData某種指針包裝? – mrplants

+0

NSData是一個只保存字節的objective-c對象。我建議使用'+(id)dataWithBytes:(const void *)字節長度:(NSUInteger)長度'。確保你將你的int數組轉換爲(const void *)。我認爲這應該工作,因爲Ints是32位。 (糾正我,如果我錯了) – Sequence

+0

另一件事。如果你打算不做複製,這種方法可能會更好。 (該鏈接可能不起作用,但該方法稱爲dataWithBytesNoCopy:length:)http://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference.html#//apple_ref/OCC/CLM/NSData的/ dataWithBytesNoCopy:長度: – Sequence