Ios 如何使用CoreGraphics重新着色图像?
我有一张灰色的画。是否有可能以其他任意颜色的阴影重新着色图像?就像下面的图片一样 我想我可以通过访问图像的每个像素并根据需要进行更改来做到这一点,但我认为可能有更好的方法Ios 如何使用CoreGraphics重新着色图像?,ios,image-processing,core-graphics,Ios,Image Processing,Core Graphics,我有一张灰色的画。是否有可能以其他任意颜色的阴影重新着色图像?就像下面的图片一样 我想我可以通过访问图像的每个像素并根据需要进行更改来做到这一点,但我认为可能有更好的方法 我希望使用CoreGraphics完成所有这些工作。我使用以下代码解决了此任务: CGContextSaveGState(bitmapContext); CGContextSetRGBFillColor(bitmapContext, red, green, blue, alpha); CGContextTranslateCT
我希望使用CoreGraphics完成所有这些工作。我使用以下代码解决了此任务:
CGContextSaveGState(bitmapContext);
CGContextSetRGBFillColor(bitmapContext, red, green, blue, alpha);
CGContextTranslateCTM(bitmapContext, 0.0, contextHeight);
CGContextScaleCTM(bitmapContext, 1.0, -1.0);
CGContextDrawImage(bitmapContext, sourceImageRect, sourceImage);
CGContextSetBlendMode(bitmapContext, kCGBlendModeColor);
CGContextFillRect(bitmapContext, sourceImageRect);
CGContextRestoreGState(bitmapContext);
CGImageRef coloredImage = CGBitmapContextCreateImage(bitmapContext);
在此代码中,bitmapContext是使用CGBitmapContextCreate创建的上下文。我使用以下代码解决了此任务:
CGContextSaveGState(bitmapContext);
CGContextSetRGBFillColor(bitmapContext, red, green, blue, alpha);
CGContextTranslateCTM(bitmapContext, 0.0, contextHeight);
CGContextScaleCTM(bitmapContext, 1.0, -1.0);
CGContextDrawImage(bitmapContext, sourceImageRect, sourceImage);
CGContextSetBlendMode(bitmapContext, kCGBlendModeColor);
CGContextFillRect(bitmapContext, sourceImageRect);
CGContextRestoreGState(bitmapContext);
CGImageRef coloredImage = CGBitmapContextCreateImage(bitmapContext);
在这段代码中,bitmapContext是用CGBitmapContextCreate创建的上下文。这有时会有一些奇怪的工件,尤其是在使用紫色覆盖白色时areas@PsychoDad可能是。你知道这个问题的解决方法吗?还没有找到。这似乎只发生在白色区域的紫色区域。我猜是iOS中的Bug。有时候会有一些奇怪的工件,尤其是在做紫色和白色的对比时areas@PsychoDad可能是。你知道这个问题的解决方法吗?还没有找到。这似乎只发生在白色区域的紫色区域。iOS中的Bug是我的猜测。