zoukankan      html  css  js  c++  java
  • C#线程的实现

    原创:
    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="图片格式不支持或写入文件发生异常!";
                }
            }
  • 相关阅读:
    mini2440移植uboot 2014.04(四)
    mini2440移植uboot 2014.04(三)
    【这些年】Linux C/C++软件开发用过的工具
    Valgrind的Memcheck快速入门
    《浪潮之巅》读后感
    三层浅析及示例分析
    C语言的代码内存布局详解
    超级立方体小记
    如何和项目经理沟通产品的交付?
    CentOS配置smaba与Windows共享文件
  • 原文地址:https://www.cnblogs.com/chinatefl/p/400555.html
Copyright © 2011-2022 走看看