问题
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