Visualizing Influence Maps in C#

The code below can be used to generate images so that you can physically see what your map looks like. To use this code, you will need to paste this method into your Document.cs, and you will need to add a reference to System.Drawing for this project. To do so, when you have the project open in visual studio, right click on NameOfTheSolution->References, click add reference, and in the search box type System.Drawing. Check the box to the left of System.Drawing and click OK. The image file will be saved as a bmp image.

///The float array used to represent the influence map. If you used a different data structure, modify this method to accept it.
///The name of the file. Do not include a file extension
private void CreateBitmapOfInfluenceMap(float[,] map, string fileName)
{
    System.Drawing.Bitmap b = new System.Drawing.Bitmap(GameManager.Instance.MapSize.x, GameManager.Instance.MapSize.y);
    for (int x = 0; x < GameManager.Instance.MapSize.x; x++)
    {
        for (int y = 0; y < GameManager.Instance.MapSize.y; y++)
        {
            b.SetPixel(x, y, System.Drawing.Color.FromArgb((int)(map[x, y] * 255), (int)(map[x, y] * 255), (int)(map[x, y] * 255)));
        }
    }
    b.Save(fileName + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
}

Leave a Reply

Your email address will not be published. Required fields are marked *