-1
    NSImage *myNewIconImage=[[NSImage imageNamed:@"FanImage"] copy];
    [myNewIconImage lockFocus];
    [@"15" drawAtPoint:NSZeroPoint withAttributes:nil];
    [myNewIconImage unlockFocus];

    [myNewIconImage setTemplate:YES];
    [[NSApplication sharedApplication]] setApplicationIconImage:myNewIconImage];
    

I am looking for a way to simply write a String onto this image.... and coming up very short. This does not worker me.

JeremyLaurenson
  • 979
  • 2
  • 11
  • 23
  • More code: NSImage *myNewIconImage=[[NSImage imageNamed:@"FanImage"] copy]; [myNewIconImage lockFocus]; [@"15" drawAtPoint:NSZeroPoint withAttributes:nil]; [myNewIconImage unlockFocus]; [myNewIconImage setTemplate:YES]; [[NSApplication sharedApplication] setApplicationIconImage:myNewIconImage]; – JeremyLaurenson May 09 '22 at 20:25

1 Answers1

0

The following code will place a mutable attributed string on an NSImage:

NSImageView *imageView = [[NSImageView alloc] initWithFrame:NSMakeRect( 0, 0, _wndW, _wndH )]; 
[[window contentView] addSubview:imageView];
NSImage *image = [NSImage imageNamed:@"myImage.jpg"];
[image lockFocus];
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
[attr setObject:[NSFont fontWithName:@"Lucida Grande" size:36] forKey:NSFontAttributeName];
[attr setObject: [NSNumber numberWithFloat: 10.0] forKey: NSStrokeWidthAttributeName];
[attr setObject:[NSColor whiteColor] forKey:NSForegroundColorAttributeName];
NSString *myStr = @"Welcome to Cocoa";
NSMutableAttributedString *s = [[NSMutableAttributedString alloc] initWithString: myStr attributes:attr];
[s drawAtPoint:NSMakePoint(130,130)];
[image unlockFocus];
[imageView setImage:image];
apodidae
  • 1,988
  • 2
  • 5
  • 9