1
我有一個int *的rgb數據,寬度,高度和scanlinestride我想創建一個NSImage。使用NSData從int *創建NSimage從NSbitmapRep?
我環顧四周,發現我需要使用NSData?
這樣做的理想方式是什麼?
我有一個int *的rgb數據,寬度,高度和scanlinestride我想創建一個NSImage。使用NSData從int *創建NSimage從NSbitmapRep?
我環顧四周,發現我需要使用NSData?
這樣做的理想方式是什麼?
使用此方法NSBitmapImageRep:
- (id)initWithBitmapDataPlanes:(unsigned char **)planes pixelsWide:(NSInteger)width pixelsHigh:(NSInteger)height bitsPerSample:(NSInteger)bps samplesPerPixel:(NSInteger)spp hasAlpha:(BOOL)alpha isPlanar:(BOOL)isPlanar colorSpaceName:(NSString *)colorSpaceName bitmapFormat:(NSBitmapFormat)bitmapFormat bytesPerRow:(NSInteger)rowBytes bitsPerPixel:(NSInteger)pixelBits
重視。它很容易使用,雖然:
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:(unsigned char **)&bitmapArray
pixelsWide:width pixelsHigh:height
bitsPerSample:8
samplesPerPixel:3 // or 4 with alpha
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0
bytesPerRow:0 // 0 == determine automatically
bitsPerPixel:0]; // 0 == determine automatically
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
[image addRepresentation:bitmap];
(unsigned char **)&bitmapArray這是一個好的強制轉換如果bitmapArray是int \ * ?? – Joe
雖然它真的是'int *'數據嗎?您需要使用'unsigned char *'來獲得每像素每通道8位。 –
據我所知,NSBitmapImageRep只接受字符。如果你有整數,你可能需要先將它轉換爲char數組。我可能是錯的 - 我只是以圖像數據作爲字符。 –