原创:
private void button1_Click(object sender, System.EventArgs e)
{
button1.Enabled=false;
ThreadStart threadDelegate = new ThreadStart(execute);
Thread thread = new Thread(threadDelegate);
thread.Start();
}
private void execute()
{
Bitmap newbmp=new Bitmap(textBox1.Text);
pictureBox1.Image=newbmp;
Bitmap bmp=(Bitmap)pictureBox1.Image;
string tmp="";
string tmp2="";
int a=0;
int b=0;
try
{
for(int j=0;j<pictureBox1.Image.Height;j=j+8)
{
tmp2="";
for(int i=0;i<pictureBox1.Image.Width;i=i+8)
{
Color pixelColor=bmp.GetPixel(i,j);
tmp="("+pixelColor.R.ToString()+","+pixelColor.G.ToString()+","+pixelColor.B.ToString()+")";
if(tmp=="(255,255,255)")
tmp2=tmp2+"0,";
else
tmp2=tmp2+"1,";
a=a+1;
}
tmp2=tmp2.Substring(0,tmp2.Length-1);
WriteFile("test.txt","MapArr["+ b +"] = new Array("+tmp2+");");
this.Text="第"+b.ToString()+"行写入成功";
b=b+1;
}
this.Text="生成成功!";
button1.Enabled = true;
}
catch
{
this.Text="图片格式不支持或写入文件发生异常!";
}
}
private void button1_Click(object sender, System.EventArgs e)
{
button1.Enabled=false;
ThreadStart threadDelegate = new ThreadStart(execute);
Thread thread = new Thread(threadDelegate);
thread.Start();
}
private void execute()
{
Bitmap newbmp=new Bitmap(textBox1.Text);
pictureBox1.Image=newbmp;
Bitmap bmp=(Bitmap)pictureBox1.Image;
string tmp="";
string tmp2="";
int a=0;
int b=0;
try
{
for(int j=0;j<pictureBox1.Image.Height;j=j+8)
{
tmp2="";
for(int i=0;i<pictureBox1.Image.Width;i=i+8)
{
Color pixelColor=bmp.GetPixel(i,j);
tmp="("+pixelColor.R.ToString()+","+pixelColor.G.ToString()+","+pixelColor.B.ToString()+")";
if(tmp=="(255,255,255)")
tmp2=tmp2+"0,";
else
tmp2=tmp2+"1,";
a=a+1;
}
tmp2=tmp2.Substring(0,tmp2.Length-1);
WriteFile("test.txt","MapArr["+ b +"] = new Array("+tmp2+");");
this.Text="第"+b.ToString()+"行写入成功";
b=b+1;
}
this.Text="生成成功!";
button1.Enabled = true;
}
catch
{
this.Text="图片格式不支持或写入文件发生异常!";
}
}