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="图片格式不支持或写入文件发生异常!";
                }
            }
  • 相关阅读:
    SD卡的控制方法(指令集和控制时序)
    MDK的优化应用(转)
    SD卡的SPI模式的初始化顺序(转)
    SD卡读写扇区注意事项(转)
    MDK下调试时提示AXF文件无法导入的解决方法(转)
    把一个 int 数字 n 格式化成16进制的字符串(前面补零成0位)
    DB9 公头母头引脚定义及连接、封装
    RS232 DB9 公头 母头 串口引脚定义
    Codeforces 91C Ski Base 加边求欧拉回路数量
    Cocos Code IDE + Lua初次使用FastTiledMap的坑
  • 原文地址:https://www.cnblogs.com/chinatefl/p/400555.html
Copyright © 2011-2022 走看看