1
나는 int *의 rgb 데이터, 너비, 높이 및 scanlinestride를 가지고 있는데, 여기서 NSImage를 만들고 싶습니다.NSData를 사용하여 int *에서 NSbitmapRep의 NSimage를 생성 하시겠습니까?
나는 주변을 둘러 보았고 NSData를 사용해야한다는 사실을 발견 했습니까?
이 작업을 수행하는 가장 이상적인 방법은 무엇입니까?
나는 int *의 rgb 데이터, 너비, 높이 및 scanlinestride를 가지고 있는데, 여기서 NSImage를 만들고 싶습니다.NSData를 사용하여 int *에서 NSbitmapRep의 NSimage를 생성 하시겠습니까?
나는 주변을 둘러 보았고 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];
(부호없는 char **) bitmapArray가 int 인 경우 괜찮아요. \ * ?? – Joe
실제로'int *'데이터입니까? 픽셀 당 채널당 8 비트를 얻으려면'unsigned char * '를 사용해야합니다. –
NSBitmapImageRep은 문자 만 허용합니다. 정수가있는 경우 먼저 char 배열로 변환해야합니다. 내가 틀렸을 수도 있습니다 - 나는 오직 문자로 이미지 데이터로 작업했습니다. –