draw Image 的两种方式:
- (NSImage *)getImage {
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(20, 20)];
[image lockFocus];
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
NSBezierPath *path = [NSBezierPath bezierPathWithOvalInrect:NSMakeRect(0, 0, 20, 20)];
[[NSColor redColor] set];
[path fill];
[image unlockFocus];
return image;
}
- (NSImage *)getImage {
NSImage *image;
image = [NSImage imageWithSize:CGSizeMake(20, 20) flipped:NO drawingHandler:^BOOL(NSRect dstRect) {
NSBezierPath *path = [NSBezierPath bezierPathWithOvalInrect:NSMakeRect(0, 0, 20, 20)];
[[NSColor redColor] set];
[path fill];
return YES;
}];
return image;
}