2010-03-22 2 views

답변

8

사용이 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]; 
+0

(부호없는 char **) bitmapArray가 int 인 경우 괜찮아요. \ * ?? – Joe

+0

실제로'int *'데이터입니까? 픽셀 당 채널당 8 비트를 얻으려면'unsigned char * '를 사용해야합니다. –

+0

NSBitmapImageRep은 문자 만 허용합니다. 정수가있는 경우 먼저 char 배열로 변환해야합니다. 내가 틀렸을 수도 있습니다 - 나는 오직 문자로 이미지 데이터로 작업했습니다. –

관련 문제