Saturday, October 13, 2018

xna - Programatically replace color gradient on sprite


Say I have the following image:




I want to tint the yellow parts on this sprites shoulder/arms by a random color. In other questions on this site, they suggest using a chroma key and replacing the constant color with whatever color I wanted, but that solution wouldn't keep the gradient.


The other solution I've seen is that I should cut out the part I want to change the color of and make it an overlay. That would work, but would require a lot of effort since I have many poses for this character + animations.


Any ideas?



Answer



You could programmatically make a mask by converting the image to HSV color space and specifying a hue range that captures the yellow parts you want while leaving alone the rest of the colors. For instance, you might select the pixels with hue between 50 and 70 (assuming yellow is a 60). Then do the tinting by adding an offset to the hue of those pixels, while keeping the same saturation and value. For example, subtracting 60 from the hue will turn the guy red, adding 60 will make him green, etc.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...