Skip to content

Instantly share code, notes, and snippets.

@jmoyers
Created May 23, 2011 21:01
Show Gist options
  • Save jmoyers/987597 to your computer and use it in GitHub Desktop.
Save jmoyers/987597 to your computer and use it in GitHub Desktop.
- (NSImage *)avatarIconForAvatar:(AvatarWrapper *)avatarWrapper
{
CGFloat red = GetRValue(avatarWrapper.avatarData.color)/255.;
CGFloat blue = GetBValue(avatarWrapper.avatarData.color)/255.;
CGFloat green = GetGValue(avatarWrapper.avatarData.color)/255.;
NSImage *avatarBody = [[NSImage alloc] initWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"avatar_icon_mask" ofType:@"png"]];
NSImage *resultImage = [[[NSImage alloc] initWithSize:[avatarBody size]] autorelease];
[resultImage lockFocus];
NSBezierPath* thePath = [NSBezierPath bezierPath];
[thePath appendBezierPathWithOvalInRect:NSMakeRect([avatarBody size].width * .10,
0,
[avatarBody size].width * .80,
[avatarBody size].height)];
[[NSColor colorWithCalibratedRed:red green:green blue:blue alpha:1.0] setFill];
[thePath fill];
[avatarBody drawAtPoint:NSMakePoint(0, 0) fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0];
[resultImage unlockFocus];
return resultImage;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment