2009-05-03 3 views
0

私はCocoaの日付で画像ファイルにタグをつけようとしており、小さなコマンドラインツールでこれを実行しようとしています。それは正常に動作します... しかし、、私は色を設定することができないようです。私は何か間違っているのですか?NSImageに描画するときの色の設定

#import <Cocoa/Cocoa.h> 

int main (int argc, const char * argv[]) { 
    [NSApplication sharedApplication]; 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
    NSImage *image = [[NSImage alloc] initWithContentsOfFile: 
       [NSString stringWithFormat:@"%s", "/some/file.png"]]; 

    if (image) { 
     [image lockFocus]; 
     NSColor *color = [NSColor whiteColor]; 
     // THESE DOESN'T SEEM TO WORK... 
     [color set]; 
     [color setStroke]; 
     [color setFill]; 
     NSString *string = [NSString stringWithFormat:@"%@", [NSDate date]]; 
     [string drawAtPoint:NSMakePoint(10, 10) withAttributes:nil]; 
     [image unlockFocus]; 

     NSBitmapImageRep *bits = [NSBitmapImageRep imageRepWithData: 
            [image TIFFRepresentation]]; 

     NSData *data = [bits representationUsingType:NSPNGFileType 
              properties:nil]; 

     [data writeToFile:@"/some/file.png" 
       atomically:NO]; 
    } 
    [pool drain]; 
    return 0; 
} 
+0

テキストの色は白ではなく黒ですか?そうでなければ、問題はおそらく他の場所にあります。 –

+0

はすべて黒です。また、[NSBezierPath fillRect:rect]を追加しようとしました。それもすべて黒です... – epatel

答えて

2

私はあなたがdrawAtPointでNSForegroundColorAttributeName属性を使用してテキストの色を設定する必要があると考えている:withAttributes:むしろsetStrokeメソッド/ setfillがより呼び出します。

+0

試してみます。しかし、set/setFillは[NSBezierPath fillRect:rect]の色を変更しませんでした。すべてが黒だった... – epatel

+0

素晴らしい仕事をした!ありがとう! :) – epatel

関連する問題