Я пытаюсь пометить файл с датой в 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