[英]Bitmap function giving parameter not valid error
首先介绍一些背景。 我是C#编程的一个相对较新的人,并且通过以下几个教程来创建游戏来学习它。 我在Win8.1上运行VS2015社区。 我正在遵循最初是在XNA下运行的游戏开发教程。 我现在要使用Windows窗体创建关卡编辑器。 到目前为止,该代码可以正常工作,并且不会出现任何问题。 遇到问题的下一步是将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();
}
}
}
Spritesheet是一个名为PlatformTiles的.png文件,位于项目的Content文件夹中。 该文件是使用Monogame的内容管理器加载的。 当我构建项目时,调试将在“ filepath”变量分配给Bitmap的行处停止。 我收到以下屏幕快照中显示的错误消息:
我已经使用Google,MSDN,Monogame和类似网站进行了尽可能多的研究。 尽管还有其他类似的实例让程序员得到了信息,但他们并未像我这样从事工作。 因此,我发布信息以寻求有关如何解决该问题的建议。 如有任何疑问,请告诉我。 谢谢。
在传递文件名时,还需要提供扩展名
string filepath = Application.StartupPath +
@"\Content\PlatformTiles.png";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.