これらのオプションを使用すると、アンチエイリアスがオフになります。左側はデフォルトのオプションです。右側、オプション付き。

UIView
サブクラスを使用している場合、これは簡単に制御できます。これは私のdrawRect
です:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, NO);
[[UIColor redColor] setStroke];
UIBezierPath *path = [self myPath];
[path stroke];
}
そして、画面をキャプチャするには、プログラムでスクリーンショットを撮る方法から
- (void)captureScreen
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data = UIImagePNGRepresentation(image);
[data writeToFile:[self screenShotFilename] atomically:YES];
}
を使用している場合、ドキュメントに記載されているように、CAShapeLayer
画面上のアンチエイリアスを制御することはできないと思います。
形状はアンチエイリアス処理されて描画され、可能な場合は常に、解像度の独立性を維持するためにラスタライズされる前に画面スペースにマッピングされます。ただし、CoreImageフィルターなど、レイヤーまたはその祖先に適用される特定の種類の画像処理操作では、ローカル座標空間でラスタライズが強制される場合があります。
ただし、画面上のアンチエイリアスに関係なく、画面のスナップショットをアンチエイリアスしないようにする場合はCGContextSetShouldAntialias
、をcaptureScreen
ルーチンに挿入できます。
- (void)captureScreen
{
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.window.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldAntialias(context, NO);
[self.window.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:[self screenShotFilename] atomically:YES];
}