• 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="图片格式不支持或写入文件发生异常!";
                }
            }
  • 相关阅读:
    C# httpclient获取cookies实现模拟web登录
    C# httpclient获取cookies实现模拟web登录
    长连接与短连接的区别以及使用场景
    长连接与短连接的区别以及使用场景
    vuejs项目性能优化总结
    vuejs项目性能优化总结
    C# 发送HTTP请求(可加入Cookies)
    C# 发送HTTP请求(可加入Cookies)
    集合框架系列教材 (十六)- 其他
    集合框架系列教材 (十五)- 关系与区别
  • 原文地址:https://www.cnblogs.com/chinatefl/p/400555.html
Copyright © 2020-2023  润新知