I'm working on an Asp.Net MVC project, and one of my requirements is to dynamically change the color of the icons on the page. An example icon is shown here:
I have been researching this the last few days, and feel that I am pretty close, however I have little graphic programming experience and need some help figuring out where I'm going wrong. Here is currently what I'm working with:
I have images on the page that look like this:
And then I have a controller Action Result that basically looks like this:
public ActionResult GetIcon(string name)
//Temporarily disregarding name and just loading up test image:
Image image = Image.FromFile(Server.MapPath("/Content/images/calendar.gif"));
Bitmap bmp = new Bitmap(image);
ColorMap map = new ColorMap;
map = new ColorMap();
map.OldColor = Color.FromArgb(46, 177, 53); //The green in the calendar image
map.NewColor = Color.FromArgb(255, 0, 0); //Red
ImageAttributes attributes = new ImageAttributes();
Graphics graphic = Graphics.FromImage(bmp);
Rectangle rectangle = new Rectangle(0, 0, bmp.Width, bmp.Height);
graphic.DrawImage(bmp, rectangle, 0, 0, rectangle.Width, rectangle.Height, graphic.PageUnit, attributes);
Byte imageBytes = null;
//Convert newly colored image to byte array.....
return File(imageBytes, "image/gif");
So my questions:
- Is the way I am attempting to change the color a correct approach?
- How do I get the newly colored image to a byte array?