Reputation: 13
I'm making a sport management game in C# - WPF. I have a template image of a person wearing a cap and shirt, representing a player.
I want to dynamically recolor the shirt and cap that the player is wearing depending on the team he's playing for. The Team object has 2 Color variables, a Primary & Secundary color.
For now I've used a Flood Fill algorithm that edits a Bitmap object. afterwards I need to convert the bitmap to an Imagesource.
The whole thing takes a fair bit of code and is fairly complext that I now doubt if I'm actually doing it in the "correct" way, or if there are better approaches to my initial goal, which is coloring an outfit to match the team colors.
(another issue I have is the flood fill is also a bit complicated if I start to use a more gradient template - for shadows for example - instead of flat colors)
Upvotes: 1
Views: 653
Reputation: 7934
Instead of using raster images like Bitmaps, you should see whether you can instead use vector graphics and WPF Path
objects.
See the MSDN for more details on Path
data: https://msdn.microsoft.com/en-us/library/ms752293(v=vs.110).aspx
This way, you can use Binding
to change the colours of the individual outfit Path
clothing item objects just by changing the underlying data object that your XAML View
is bound to. The other advantage to using Path
objects is that because it's vector data, the images will scale without pixellation regardless of the resolution your game is being run at.
Upvotes: 1