Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在二维阵列中显示图像的多个实例_C#_Arrays_Image - Fatal编程技术网

C# 在二维阵列中显示图像的多个实例

C# 在二维阵列中显示图像的多个实例,c#,arrays,image,C#,Arrays,Image,这是我决定从一个名为btnCreate的winForm&1按钮开始的,我有两个图像35px X 35px floor.bmp和wall.bmp public partial class Form1 : Form { int x; int y; int[] Row0 = new int[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; int[] Row1 = new int[10] { 1, 1, 1, 1, 0, 0, 1, 1, 0,

这是我决定从一个名为btnCreate的winForm&1按钮开始的,我有两个图像35px X 35px floor.bmp和wall.bmp

public partial class Form1 : Form
{
    int x;
    int y;
    int[] Row0 = new int[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
    int[] Row1 = new int[10] { 1, 1, 1, 1, 0, 0, 1, 1, 0, 1 };
    int[] Row2 = new int[10] { 1, 1, 0, 0, 0, 0, 1, 1, 0, 1 };
    int[] Row3 = new int[10] { 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 };
    int[] Row4 = new int[10] { 1, 0, 0, 1, 0, 1, 0, 0, 0, 1 };
    int[] Row5 = new int[10] { 1, 0, 0, 1, 0, 0, 0, 1, 0, 1 };
    int[] Row6 = new int[10] { 1, 1, 0, 0, 0, 0, 1, 1, 0, 1 };
    int[] Row7 = new int[10] { 1, 1, 1, 1, 0, 0, 1, 1, 0, 1 };
    int[] Row8 = new int[10] { 1, 1, 0, 0, 0, 0, 1, 1, 0, 1 };
    int[] Row9 = new int[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
    int[,] LevelA = new int[10,10];

    private void Form1_Load(object sender, EventArgs e)
    {
        for (x = 0; x < 10; x++)
        {
            //load all arrays 
            LevelA[0, x] = Row0[x];
            LevelA[1, x] = Row1[x];
            LevelA[2, x] = Row2[x];
            LevelA[3, x] = Row3[x];
            LevelA[4, x] = Row4[x];
            LevelA[5, x] = Row5[x];
            LevelA[6, x] = Row6[x];
            LevelA[7, x] = Row7[x];
            LevelA[8, x] = Row8[x];
            LevelA[9, x] = Row9[x];
        }
    }

    private void btnCreate_Click(object sender, EventArgs e)
    {
        for (int X = 0; X < 10; X++)
        {
            for (int Y = 0; Y < 10; Y++)
            {
                //the following is the idea of what I would like to accomplish
                //if (LevelA[Y,X] == 0)
                //{
                    //Bitmap myBmp = new Bitmap(Image.FromFile(@"C:\My Documents\floor2.bmp"));
                    //myBmp.Top == Y * 35;
                    //myBmp.left == X * 35;
                //}
            }
        }
    }
}
公共部分类表单1:表单
{
int x;
int-y;
int[]Row0=新的int[10]{1,1,1,1,1,1,1,1};
int[]Row1=新的int[10]{1,1,1,0,0,1,1,0,1};
int[]Row2=新的int[10]{1,1,0,0,0,0,1,1,0,1};
int[]Row3=新的int[10]{1,1,1,1,0,1,1,1,0,1};
int[]Row4=新的int[10]{1,0,0,1,0,1,0,0,1};
int[]Row5=新的int[10]{1,0,0,0,1,0,0,0,1,0,1};
int[]Row6=新的int[10]{1,1,0,0,0,0,1,1,0,1};
int[]Row7=新的int[10]{1,1,1,0,0,1,1,0,1};
int[]Row8=新的int[10]{1,1,0,0,0,0,1,1,0,1};
int[]Row9=新的int[10]{1,1,1,1,1,1,1,1};
int[,]LevelA=新的int[10,10];
私有void Form1\u加载(对象发送方、事件参数e)
{
对于(x=0;x<10;x++)
{
//加载所有阵列
LevelA[0,x]=行0[x];
LevelA[1,x]=行1[x];
LevelA[2,x]=行2[x];
LevelA[3,x]=第3行[x];
LevelA[4,x]=第4行[x];
LevelA[5,x]=第5行[x];
LevelA[6,x]=第6行[x];
LevelA[7,x]=第7行[x];
LevelA[8,x]=第8行[x];
LevelA[9,x]=第9行[x];
}
}
私有void b创建\u单击(对象发送者,事件参数e)
{
对于(int X=0;X<10;X++)
{
对于(int Y=0;Y<10;Y++)
{
//以下是我想要完成的想法
//if(LevelA[Y,X]==0)
//{
//位图myBmp=新位图(Image.FromFile(@“C:\My Documents\floor2.bmp”);
//myBmp.Top==Y*35;
//myBmp.left==X*35;
//}
}
}
}
}

上面的代码是否也能像我预期的那样工作>?或者for循环的末尾是否只显示最后一个磁贴,因为它将继续用新的磁贴替换(销毁)前一个磁贴?在这种情况下,10 x 10网格需要100 myBmp?

您可以通过创建
位图
对象来获取图像文件的位图

 Bitmap bmp = new Bitmap(Image.FromFile(@"D:\MyImageFile.bmp"));
只要掌握了
图形
实例,就可以将其放置或绘制到任何位置。
您可以找到一个简单的例子。

请尝试修复班次/上限锁定,并在您的帖子中添加一些大写字母。另外,尽量不要添加不相关的“我不太聪明/谢谢你/lol”和类似文本。拼写和语法在这里很重要。我已经编辑了我的代码,很抱歉拼写不好,我会做得更好汉克斯·詹姆斯,我认为这是正确的想法,我的上述问题不像我想象的那样容易理解。。让我把我的密码。。