0

NSBitmapImageRep를 반환하는 메서드를 구현했습니다. 해당 비트 맵에 10x2 직사각형을 그려야하며 각 직사각형은 청록색으로 채워 져야합니다. 그러나 각 사각형에 대해 시안 값은 12 씩 증가해야합니다 (값은 0에서 시작 함).NSBitmapImageRep에서 드로잉 중 색 변경

결과 비트 맵은 예상대로 20 개의 직사각형을 가져옵니다. 그러나 사각형 사이의 색상은 다릅니다. 모든 사각형은 동일한 청록색 값을 갖습니다.

나는 무엇이 문제인지 전혀 모른다. 누군가 나에게 힌트를 주시겠습니까?

-(NSBitmapImageRep*)drawOntoBitmap 
{ 
    NSRect offscreenRect = NSMakeRect(0.0, 0.0, 1000.0, 400.0); 
    NSBitmapImageRep *image = nil; 

    image = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil 
                pixelsWide:offscreenRect.size.width 
                pixelsHigh:offscreenRect.size.height 
               bitsPerSample:8 
               samplesPerPixel:4 
                hasAlpha:NO 
                isPlanar:NO 
               colorSpaceName:NSDeviceCMYKColorSpace 
               bitmapFormat:0 
                bytesPerRow:(4 * offscreenRect.size.width) 
               bitsPerPixel:32]; 

    [NSGraphicsContext saveGraphicsState]; 
    [NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:image]]; 

    NSRect colorRect; 
    NSBezierPath *thePath; 
    int cyan = 0; 
    int x = 0; 
    int y = 0; 
    int w = 0; 
    int h = 0; 
    for (intj = 0; j<2; j++) 
    { 
     y = j * 200; 
     h = y + 200; 

     for (int i = 0; i<10; i++) 
     { 
      x = i * 100; 
      w = x + 100; 

      colorRect = NSMakeRect(x, y, w, h); 
      thePath = [NSBezierPath bezierPathWithRect: colorRect]; 
      cyan += 12; 
      [[NSColor colorWithDeviceCyan:cyan magenta:0 yellow:0 black:0 alpha:100] set]; 
      [thePath fill]; 
     } 
    } 

    [NSGraphicsContext restoreGraphicsState]; 
    return image; 
} 

각 직사각형에 대해 동일한 색상 값이 사용되며 두 루프가 전달 된 후 마지막 청록색 값이 사용됩니다.

답변

0

OK, NSColor 값의 범위는 0.0 - 1.0입니다. 그래서 나는 그렇게 떠 내 시안을 설정해야합니다 :

cyan += 12/255; 

값은 1.0 이하이어야한다.