Resize CGImageRef without anti-liasing

可紊 提交于 2019-12-05 01:58:28

问题


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)


回答1:


try CGContextSetInterpolationQuality:

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


来源:https://stackoverflow.com/questions/7232729/resize-cgimageref-without-anti-liasing

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