How to prevent the pixels from becoming blurry when I enlarge an image in my color pick project for iOS?

。_饼干妹妹 提交于 2019-12-13 08:59:54

问题


I'm making a little project that provides the ability to enlarge an image and pick pixels' colors from the magnifier, now I can magnify the touched place of the image, but the magnifier shows the pixels with blurry effect, how can I make it show the pixels one by one very clearly without any fuzzy processing?

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

Should be:

Should not be:


回答1:


You want to set a drawing mode that scaled pixels rather than interpolating. I think for the drawing you're doing you want the CGContext command CGContextSetInterpolationQuality, with a value of kCGInterpolationNone.

(Disclaimer: I think this is the setting, but I'm not positive, and haven't tried it.)

BTW, it's probably best to avoid images that anywhere close to NSFW on this site. This site is read all over the world, and I'm sure plenty of people read it at work. Different workplaces have widely different standards of what's acceptable. Your sample image is pretty risqué.



来源:https://stackoverflow.com/questions/27188456/how-to-prevent-the-pixels-from-becoming-blurry-when-i-enlarge-an-image-in-my-col

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!