0

First some background. I a relative new to C# programming and have been lear ning it by creating games following several tutorials. I am running VS2015 Community on Win8.1. I am following a game development tutorial that was originally written to be run under XNA. I am at the point where I am creating a level editor using Windows Forms. So far the code is working as the level editor form displays without problems. The next step, with which I am having the issue, is to load a spritesheet into the editor so levels can be created/modified. Here is the method to load the spritesheet:

private void LoadImageList()
    {
        string filepath = Application.StartupPath +
           @"\Content\PlatformTiles";
       Bitmap tileSheet = new Bitmap(filepath);
        int tilecount = 0;
        for (int y = 0; y < tileSheet.Height / TileMap.TileHeight; y++)
        {
            for (int x = 0; x < tileSheet.Width / TileMap.TileWidth; x++)
            {
                Bitmap newBitmap = tileSheet.Clone(new
                    System.Drawing.Rectangle(
                        x * TileMap.TileWidth,
                        y * TileMap.TileHeight,
                        TileMap.TileWidth,
                        TileMap.TileHeight),
                        System.Drawing.Imaging.PixelFormat.DontCare);

                imgListTiles.Images.Add(newBitmap);
                string itemName = "";
                if (tilecount == 0)
                {
                    itemName = "Empty";
                }
                if (tilecount == 1)
                {
                    itemName = "White";
                }
                listTiles.Items.Add(new
                    ListViewItem(itemName, tilecount++));
            }
        }
    }

    private void MapEditor_Load(object sender, EventArgs e)
    {
        LoadImageList();
    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        game.Exit();
        Application.Exit();
    }
  }
}

The spritesheet is a .png file named PlatformTiles and located in the Content folder for the project. The file was loaded using Monogame's Content manager. When I build the project, Debug stops at the line where the "filepath" variable is being assigned to Bitmap. I get the error message shown in the following screen shot:

enter image description here

I have researched as much as I could using Google, MSDN, Monogame, and similar sites. Though there are other similar instances of programmers getting the message, they are not working on things like I am. So I am posting to get advice on what I can do to fix the problem. If there are any questions please let me know. Thank you.

Olivier De Meulder
  • 2,493
  • 3
  • 25
  • 30
Devbyskc
  • 1
  • 1
  • Under Monogame you don't need the extension. When you load assets into your program the Content Manager assigns an internal extension to manage the asset files. It is similar to what XNA did in converting files to xnb. I've written 4 or 5 game programs using VS with Monogame and had no issues leaving off the extension. But now that you mention it, could the issue be I'm using Bitmap where I was not before? Does Bitmap require the extension to read in the string? I'll try it and see if it makes a difference. Thanks! – Devbyskc Apr 16 '16 at 14:21

1 Answers1

1

You need to give the extension as well when you're passing in the filename

string filepath = Application.StartupPath +
           @"\Content\PlatformTiles.png";
Barry O'Kane
  • 1,189
  • 7
  • 12