如何在我的iOS拾色项目中放大图像时防止像素变得模糊?

我正在做一个能够放大图像并从放大镜中选取像素颜色的小工程,现在我可以放大图像的触摸位置,但是放大镜显示的是模糊效果的像素,我怎样才能使它不用模糊处理就可以一目了然地显示像素了吗?

- (void)drawRect:(CGRect)rect { CGContextRef context = UIGraphicsGetCurrentContext(); CGRect bounds = self.bounds; CGImageRef mask = [UIImage imageNamed: @"loupe-mask@2x.png"].CGImage; UIImage *glass = [UIImage imageNamed: @"loupe-hi@2x.png"]; CGContextSaveGState(context); CGContextClipToMask(context, bounds, mask); CGContextFillRect(context, bounds); CGContextScaleCTM(context, 40, 40); //draw your subject view here CGContextTranslateCTM(context,1*(self.frame.size.width*0.5),1*(self.frame.size.height*0.5)); //CGContextScaleCTM(context, 1.5, 1.5); CGContextTranslateCTM(context,-1*(touchPoint.x),-1*(touchPoint.y)); [self.viewToMagnify.layer renderInContext:context]; CGContextRestoreGState(context); [glass drawInRect: bounds]; } 

应该:

在这里输入图像说明

不应该是:

在这里输入图像说明

您要设置缩放像素而不是插值的绘图模式。 我认为你正在做的绘图你想CGContext命令CGContextSetInterpolationQuality,值为kCGInterpolationNone。

(免责声明:我认为这是设置,但我不积极,并没有尝试过。)

顺便说一句,这可能是最好的,以避免在这个网站上任何地方靠近NSFW的图像。 这个网站是全世界读的,我相信有很多人在工作中阅读。 不同的工作场所可接受的标准差别很大。 你的示例图像很漂亮。