这就是我决定从winForm& 1个按钮叫做btnCreate,我有2个图像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;
//}
}
}
}
}
上面的CODE是否也会按照我的意图工作&gt;?或者for-loop的结尾只显示最后一个tile,因为它会用新的tile替换(销毁)前一个tile?在女巫的情况下,我需要100个myBmp用于10乘10格?
答案 0 :(得分:0)
您可以通过创建Bitmap
对象来获取图像文件的位图。
Bitmap bmp = new Bitmap(Image.FromFile(@"D:\MyImageFile.bmp"));
只要您掌握Graphics
个实例,就可以放置它或绘制它。
您可以找到关于此的简单示例here。