19. Converting color
NewColorMap is a ColorMap object its particular job is to replace all pixels of a specific color on a picture by another color, useful if you want to paint your players by another color, for example changing the color of his eyes, his hair, skin ...
You have to make sure that the color to be changed is present only in the area you want, assuming the color of the eyes of your player is blue and his shoulder is also blue, then if you change the blue color to another one it's going to be done to his shoulders too. in that case you need to make the color of his eyes unique and not present somewhere else.
To demonstrate this let’s take an example.
So this is the original picture
And we want to change his pant's color, then We need to pick a color from its pant this
So the old value is
Red = 248
Green = 144
Blue = 8
To a new color, and to find your RGB color you just need to use same tool "Photoshop" the ColorPicker
Red = 37
Green = 97
Blue = 219
Now you got the RGB colors we can convert it.
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using MELHARFI.Manager;
using MELHARFI.Manager.Gfx;
namespace _2dProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Manager manager = new Manager(this, "CORE_ENGINE");
manager.Background = Color.WhiteSmoke;
Bmp naruto = new Bmp(@"narutoStep1.png", new Point(100, 100), "naruto", Manager.TypeGfx.Object, true, manager);
// determine how many instances of converting color we are using, ColorMap[1] mean only 1 color will be converted
naruto.NewColorMap = new System.Drawing.Imaging.ColorMap[1];
// calling the constructor of ColorMap for initialization
naruto.NewColorMap[0] = new System.Drawing.Imaging.ColorMap();
// OldColor is the color to be replaced, you need to use a paint tool to pick the color value like photoshop
naruto.NewColorMap[0].OldColor = Color.FromArgb(248, 144, 8);
// replacing the OldColor by new ones
naruto.NewColorMap[0].NewColor = Color.FromArgb(37, 97, 219);
manager.ObjectLayer.Add(naruto);
}
}
}
It's a zoomed picture, so you can see that even his hair has been painted too because it has some of the same color we want to change.
So i'll not make shour to handle this issue because i told you how to "by coloring your player's parts whith unic colors" but we will talk about another issue.
If you look closely you see that not all of his pant has been colored, because there's a gradient of color of the one we changed, so you need to pick that color too and change it depending on the gradient you want.
So what we want is that we need to change many colors of that player and we dont need to reproduce the code above, but just add the others colors to the ColorMap as bellow
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using MELHARFI.Manager;
using MELHARFI.Manager.Gfx;
namespace _2dProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Manager manager = new Manager(this, "CORE_ENGINE");
manager.Background = Color.WhiteSmoke;
Bmp naruto = new Bmp(@"narutoStep1.png", new Point(100, 100), "naruto", Manager.TypeGfx.Object, true, manager);
// determine how many instances of converting color we are using, ColorMap[1] mean only 1 color will be converted
naruto.NewColorMap = new System.Drawing.Imaging.ColorMap[1]; // first color to be changed
naruto.NewColorMap = new System.Drawing.Imaging.ColorMap[2]; // second one
// calling the constructor of ColorMap for initialization
naruto.NewColorMap[0] = new System.Drawing.Imaging.ColorMap();
naruto.NewColorMap[1] = new System.Drawing.Imaging.ColorMap();
// OldColor is the color to be replaced, you need to use a paint tool to pick the color value like photoshop
naruto.NewColorMap[0].OldColor = Color.FromArgb(248, 144, 8);
naruto.NewColorMap[1].OldColor = Color.FromArgb(192, 56, 0);
// replacing the OldColor by new ones
naruto.NewColorMap[0].NewColor = Color.FromArgb(37, 97, 219);
naruto.NewColorMap[1].NewColor = Color.FromArgb(29, 73, 161);
manager.ObjectLayer.Add(naruto);
}
}
}
Huum it's look's like there's a third color to be convertted to in the edge of the pant, let's add the third one then :
using System;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using MELHARFI.Manager;
using MELHARFI.Manager.Gfx;
namespace _2dProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Manager manager = new Manager(this, "CORE_ENGINE");
manager.Background = Color.WhiteSmoke;
Bmp naruto = new Bmp(@"narutoStep1.png", new Point(100, 100), "naruto", Manager.TypeGfx.Object, true, manager);
// determine how many instances of converting color we are using, ColorMap[1] mean only 1 color will be converted
naruto.NewColorMap = new System.Drawing.Imaging.ColorMap[1]; // first color to be changed
naruto.NewColorMap = new System.Drawing.Imaging.ColorMap[2]; // second one
naruto.NewColorMap = new System.Drawing.Imaging.ColorMap[3]; // third one
// calling the constructor of ColorMap for initialization
naruto.NewColorMap[0] = new System.Drawing.Imaging.ColorMap();
naruto.NewColorMap[1] = new System.Drawing.Imaging.ColorMap();
naruto.NewColorMap[2] = new System.Drawing.Imaging.ColorMap();
// OldColor is the color to be replaced, you need to use a paint tool to pick the color value like photoshop
naruto.NewColorMap[0].OldColor = Color.FromArgb(248, 144, 8);
naruto.NewColorMap[1].OldColor = Color.FromArgb(192, 56, 0);
naruto.NewColorMap[2].OldColor = Color.FromArgb(128, 24, 0);
// replacing the OldColor by new ones
naruto.NewColorMap[0].NewColor = Color.FromArgb(37, 97, 219);
naruto.NewColorMap[1].NewColor = Color.FromArgb(29, 73, 161);
naruto.NewColorMap[2].NewColor = Color.FromArgb(14, 29, 59);
manager.ObjectLayer.Add(naruto);
}
}
}
Now the pant is fully painted with color gradient.
Want me to dev an app for you ? dont hesitate to contact me.
Are you looking for a coder/teammate for your project ? Let's give it a try.
Have a proposal for me ? we can discuss about it.
You want to buy me a coffe ? m.elharfi@gmail.com