Resize CGImageRef without anti-liasing
Asked Answered
R

1

5

I am trying to resize a 10x10 pixel CGImageRef, captured like this:

CGImageRef imageRef = CGImageCreateWithImageInRect(screenShot, CGRectMake(mouseLoc.x-5, screen_height-mouseLoc.y-5, 10, 10));

CGContextRef mainViewContentContext = CGBitmapContextCreate (NULL, maskImage.size.width, maskImage.size.height, 8, maskImage.size.height*4, colorSpace, kCGImageAlphaPremultipliedFirst);

CGContextDrawImage(mainViewContentContext, NSMakeRect(0,0, maskImage.size.width, maskImage.size.height), imageRef);

Then I need to make a 250x250 pixel image like this this, but the upscaled image looks like there is anti aliasing on it (looks like this)

Roxannroxanna answered 29/8, 2011 at 16:10 Comment(2)
Interesting question. Most of the time people are asking for the reverse.Flexuosity
Just for people's reference and ease of Googling, what's happening here is called interpolation, not antialiasing.Monosymmetric
C
6

try CGContextSetInterpolationQuality:

// disable interpolation like this:
CGContextSetInterpolationQuality(mainViewContentContext, kCGInterpolationNone);
// now draw
Conditioning answered 29/8, 2011 at 17:7 Comment(2)
same thing :( I'm not getting perfect pixelsRoxannroxanna
@Roxannroxanna i misread your question. the example i made enforces HQ interpolation - updating...Conditioning

© 2022 - 2024 — McMap. All rights reserved.