我正在尝试以编程方式绘制到 UIImage 中,如下所示:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIGraphicsBeginImageContextWithOptions(CGSizeMake(2, 2), YES, 1);
CGContextRef context = UIGraphicsGetCurrentContext();
// These three lines of code apparently do nothing.
CGContextSetInterpolationQuality(context, kCGInterpolationNone);
CGContextSetAllowsAntialiasing(context, false);
CGContextSetShouldAntialias(context, false);
CGContextSetFillColorWithColor(context, [UIColor colorWithRed:1 green:0 blue:0 alpha:1].CGColor);
CGContextFillRect(context, CGRectMake(0, 0, 1, 1));
self.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
此代码有效,只是生成的图像非常柔和,显然是由于抗锯齿/插值的积极尝试。我需要使用最近邻插值来缩放图像。如何防止这种抗锯齿?
谢谢!