私は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;
}
テキストの色は白ではなく黒ですか?そうでなければ、問題はおそらく他の場所にあります。 –
はすべて黒です。また、[NSBezierPath fillRect:rect]を追加しようとしました。それもすべて黒です... – epatel