Pregunta

Estoy tratando de etiquetar un archivo de imagen con una fecha en Cocoa y estoy tratando de hacerlo en una pequeña herramienta de línea de comando. Funciona bien ... pero , parece que no puedo establecer el color. ¿Estoy haciendo algo mal?

#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;
}
¿Fue útil?

Solución

Creo que necesita establecer el color del texto usando el atributo NSForegroundColorAttributeName en drawAtPoint: withAttributes: call, en lugar de setStroke / setFill.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top