在没有消除锯齿的情况下调整CGImageRef的大小

时间:2011-08-29 16:10:42

标签: objective-c xcode scaling nsimage cgimageref

我正在尝试调整10x10像素CGImageRef的大小,像这样捕获:

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);

然后我需要像这样this制作250x250像素的图像,但放大的图像看起来像是有抗锯齿(看起来像this

1 个答案:

答案 0 :(得分:5)

尝试CGContextSetInterpolationQuality

// disable interpolation like this:
CGContextSetInterpolationQuality(mainViewContentContext, kCGInterpolationNone);
// now draw