Here is my code, it is simple and should work, but doesn't and it's driving me crazy. I troubleshooted every part of it, everything is working as expected but when i open my file no matter what composes my bitmap it's just full of 0.
Here's the code:
public void saveToolStripButton_Click(object sender, EventArgs e)
{
int[,] map = new int[xs,ys];
int yt, xt;
yt = 0;
Color pixcolor;
while ( yt < ys)
{
xt = 0;
while (xt < xs)
{
pixcolor = drawg.myBitmap.GetPixel(xt, yt);
if (pixcolor == Color.Green)
{
map[xt, yt] = 0;
}
if (pixcolor == Color.Black)
{
map[xt, yt] = 1;
}
if (pixcolor == Color.White)
{
map[xt, yt] = 2;
}
if (pixcolor == Color.Red)
{
map[xt, yt] = 3;
}
if (pixcolor == Color.DarkGreen)
{
map[xt, yt] = 4;
}
if (pixcolor == Color.Gray)
{
map[xt, yt] = 5;
}
if (pixcolor == Color.IndianRed)
{
map[xt, yt] = 6;
}
if (pixcolor == Color.Gold)
{
map[xt, yt] = 7;
}
xt++;
}
yt++;
}
System.IO.StreamWriter file = new System.IO.StreamWriter("c:\\test.txt");
for (int yl = 0; yl < ys; yl++)
{
for (int xl = 0; xl < xs; xl++)
{
file.Write(map[xl,yl].ToString());
}
file.Write(Environment.NewLine);
}
file.Close();
}
xs and ys are just the dimension of the bitmap.The format of the bitmap is Format24bppRgb. I have no idea why it wont work, probably something stupid i overlooked.
Thanks alot.