简体   繁体   English

位图函数给出参数无效错误

[英]Bitmap function giving parameter not valid error

First some background. 首先介绍一些背景。 I a relative new to C# programming and have been lear ning it by creating games following several tutorials. 我是C#编程的一个相对较新的人,并且通过以下几个教程来创建游戏来学习它。 I am running VS2015 Community on Win8.1. 我在Win8.1上运行VS2015社区。 I am following a game development tutorial that was originally written to be run under XNA. 我正在遵循最初是在XNA下运行的游戏开发教程。 I am at the point where I am creating a level editor using Windows Forms. 我现在要使用Windows窗体创建关卡编辑器。 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. 遇到问题的下一步是将Spritesheet加载到编辑器中,以便可以创建/修改关卡。 Here is the method to load the spritesheet: 这是加载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. Spritesheet是一个名为PlatformTiles的.png文件,位于项目的Content文件夹中。 The file was loaded using Monogame's Content manager. 该文件是使用Monogame的内容管理器加载的。 When I build the project, Debug stops at the line where the "filepath" variable is being assigned to Bitmap. 当我构建项目时,调试将在“ filepath”变量分配给Bitmap的行处停止。 I get the error message shown in the following screen shot: 我收到以下屏幕快照中显示的错误消息:

在此处输入图片说明

I have researched as much as I could using Google, MSDN, Monogame, and similar sites. 我已经使用Google,MSDN,Monogame和类似网站进行了尽可能多的研究。 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. 谢谢。

You need to give the extension as well when you're passing in the filename 在传递文件名时,还需要提供扩展名

string filepath = Application.StartupPath +
           @"\Content\PlatformTiles.png";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM