Is programmatically inverting the colors of an image possible?

后端 未结 7 1877
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 07:00

I want to take an image and invert the colors in iOS.

7条回答
  •  隐瞒了意图╮
    2020-11-28 07:49

    Sure, it's possible-- one way is using the "difference" blend mode (kCGBlendModeDifference). See this question (among others) for the outline of the code to set up the image processing. Use your image as the bottom (base) image, and then draw a pure white bitmap on top of it.

    You can also do the per-pixel operation manually by getting the CGImageRef and drawing it into a bitmap context, and then looping over the pixels in the bitmap context.

提交回复
热议问题