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

时间:2014-11-28 12:14:53

标签: ios objective-c uiimageview uiimage magnify

我正在做一个小项目,提供放大图像和从放大镜中选择像素颜色的能力,现在我可以放大图像的触摸位置,但放大镜显示像素模糊效果,怎么能我让它一个接一个地显示像素,没有任何模糊处理?

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

应该是:

enter image description here

不应该:

enter image description here

1 个答案:

答案 0 :(得分:1)

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

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

顺便说一句,最好避免在这个网站上任何靠近NSFW的图像。这个网站遍布世界各地,我相信很多人都会在工作中阅读它。不同的工作场所对可接受的标准有着广泛的不同。您的样本图像非常危险。