-1

我正在制作一个小项目,可以放大图像并从放大镜中选择像素的颜色,现在我可以放大图像的触摸位置,但是放大镜显示的像素具有模糊效果,我该怎么做没有任何模糊处理,非常清楚地显示像素点?

- (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];
}

应该:

在此处输入图像描述

不该是:

在此处输入图像描述

4

1 回答 1

1

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

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

顺便说一句,最好避免在此站点上任何接近 NSFW 的图像。这个网站在世界各地都有人阅读,我相信很多人在工作中阅读它。不同的工作场所对可接受的标准有很大不同。您的示例图像非常有伤风化。

于 2014-11-28T13:28:28.240 回答