How do I recolor an image? (see images)

后端 未结 7 619
没有蜡笔的小新
没有蜡笔的小新 2020-12-29 08:53

How do I achieve this kind of color replacement programmatically? \"replacing


So this i

7条回答
  •  伪装坚强ぢ
    2020-12-29 09:09

    The formula for calculating the new pixel is:

    newColor.R = OldColor;
    newColor.G = OldColor;
    newColor.B = 255;
    

    Generalizing to arbitrary colors:

    I assume you want to map white to white and black to that color. So the formula is newColor = TargetColor + (White - TargetColor) * Input

    newColor.R = OldColor + (1 - oldColor / 255.0) * TargetColor.R;
    newColor.G = OldColor + (1 - oldColor / 255.0) * TargetColor.G;
    newColor.B = OldColor + (1 - oldColor / 255.0) * TargetColor.B;
    

    And then just iterate over the pixels of the image(byte array) and write them to a new RGB array. There are many threads on how to copy an image into a byte array and manipulate it.

提交回复
热议问题