Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I turn off all the image processing to see actual, unmodified pixels when I zoom way in?

I have an app that needs to zoom far enough into images that I can clearly see the individual pixels on an image. I need to see clear squares of one color, with no anti-aliasing or other of the usually-helpful techniques for making images look good on a display. How do I stifle all this help? Here is code that works, but zooms into blurry, adjusted pixels:

- (void)drawRect:(CGRect)rect {
    CGRect photoRect = CGRectMake(currentTarget.origin.x,
                                  currentTarget.origin.y,
                                  currentTarget.size.width,
                                  currentTarget.size.height);
    CGContextRef context = UIGraphicsGetCurrentContext() ;
    CGContextSaveGState(context);
    CGImageRef subImageRef = 
        CGImageCreateWithImageInRect(sourceImage.CGImage, photoRect);
    UIImage *subImage = [UIImage imageWithCGImage:subImageRef];
    [subImage drawInRect:rect];
    CGImageRelease(subImageRef);
    CGContextRestoreGState(context);
    CGContextFlush(context);
}
like image 373
Bill Cheswick Avatar asked Jul 13 '17 11:07

Bill Cheswick


1 Answers

Setting the interpolation quality for the context should help resolve this issue, although if you're allowing the user to zoom beyond the 1:1 pixel ratio, things will still look somewhat soft.

CGContextSetInterpolationQuality(context, kCGInterpolationNone)

In this instance, I've used kCGInterpolationNone which is effectively "nearest neighbour".

For more information see Apple's reference documentation.

like image 67
John Parker Avatar answered Oct 12 '22 22:10

John Parker