Frage

Ich versuche, eine Bilddatei mit einem Datum in Cocoa zu markieren, und versuche, dies in einem kleinen Kommandozeilen-Tool zu tun. Es funktioniert gut ... und , ich kann nicht scheinen zu können, um die Farbe einzustellen. Mache ich etwas falsch?

#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;
}
War es hilfreich?

Lösung

Ich glaube, Sie die Farbe des Textes festlegen müssen das NSForegroundColorAttributeName Attribut in dem drawAtPoint mit: withAttributes: rufen, anstatt setStroke / setFill

.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top