NSBitMapImageRep
サブピクセルアンチエイリアシングを使用してテキストを描画する方法はありますか?テキストは不透明な白い背景に描かれていて、このCGContextSetShouldSmoothFonts
関数を使ってみましたが、役に立たないようです。
NSBitmapImageRep *bm = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:300 pixelsHigh:300 bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSCalibratedRGBColorSpace bytesPerRow:0 bitsPerPixel:0];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:bm]];
[[NSColor whiteColor] set];
NSRectFill(NSMakeRect(0, 0, 300, 300));
CGContextRef ctx = NSGraphicsContext.currentContext.graphicsPort;
CGContextSetShouldSmoothFonts(ctx, true);
[@"Example" drawAtPoint:NSZeroPoint withAttributes:nil];
[[bm TIFFRepresentation] writeToFile:[@"~/Desktop/bitmap.tiff" stringByExpandingTildeInPath] atomically:NO];
NSImage
を使用して描画するとテキストスムージングを機能させることができます-[NSImage lockFocus]
が、Retinaディスプレイで実行する場合は信頼できません。