当我放大时,如何关闭所有图像处理以查看实际的、未修改的像素?

How do I turn off all the image processing to see actual, unmodified pixels when I zoom way in?

我有一个应用程序需要将图像放大到足够远,以便我可以清楚地看到图像上的各个像素。我需要看到一种颜色的清晰方块,没有抗锯齿或其他通常有助于使图像在显示器上看起来不错的技术。我如何扼杀所有这些帮助?这是有效的代码,但放大到模糊、调整后的像素:

- (void)drawRect:(CGRect)rect {
    CGRect photoRect = CGRectMake(currentTarget.origin.x,
                                  currentTarget.origin.y,
                                  currentTarget.size.width,
                                  currentTarget.size.height);
    CGContextRef context = UIGraphicsGetCurrentContext() ;
    CGContextSaveGState(context);
    CGImageRef subImageRef = 
        CGImageCreateWithImageInRect(sourceImage.CGImage, photoRect);
    UIImage *subImage = [UIImage imageWithCGImage:subImageRef];
    [subImage drawInRect:rect];
    CGImageRelease(subImageRef);
    CGContextRestoreGState(context);
    CGContextFlush(context);
}

为上下文设置插值质量应该有助于解决这个问题,但如果您允许用户缩放超过 1:1 像素比率,看起来仍然会有些柔和。

CGContextSetInterpolationQuality(context, kCGInterpolationNone)

在这种情况下,我使用了 kCGInterpolationNone,实际上是 "nearest neighbour"。

有关详细信息,请参阅 Apple's reference documentation