public static bool SaveSetting(SavePos SettingInput) { string curpath = "Settings\\setting"; try { SaveObj(SettingInput, curpath); } catch { //写入失败 return(false); } SavePos test = new SavePos(); try { test = (SavePos)LoadObj(curpath); //resave_setting(); return(true); } catch { } return(false); }
private void Form1_Load(object sender, EventArgs e) { //读取配置 if (Device_control.SettingExist()) { //已有配置 } else { //初次配置 //SetMeAutoStart(true); //Form3 frm3 = new Form3(); //frm3.ShowDialog(); } curz = Device_control.LoadSetting(); //timer1.Start(); //todo添加判断计算机名重复 textBox1.Text = curz.Red_x; textBox2.Text = curz.Red_y; textBox3.Text = curz.Green_x; textBox4.Text = curz.Green_y; textBox5.Text = curz.Blue_x; textBox6.Text = curz.Blue_y; textBox7.Text = curz.Yellow_x; textBox8.Text = curz.Yellow_y; textBox9.Text = curz.Black_x; textBox10.Text = curz.Black_y; textBox11.Text = curz.x_pixel.ToString(); //textBox12.Text = curz.y_pixel.ToString(); }
public static SavePos LoadSetting() { string curpath = "Settings\\setting"; SavePos test = new SavePos(); try { test = (SavePos)LoadObj(curpath); } catch { //copy_setting(); //test = (SavePos)LoadObj(curpath); } return(test); }
/// <summary> /// 已存在配置文件目录返回true 不存在则创建目录 /// </summary> /// <returns></returns> public static bool SettingExist() { string curuserpath = "Settings\\"; if (Directory.Exists(curuserpath)) { return(true); } else { //没有则新建setting System.IO.Directory.CreateDirectory(curuserpath); System.IO.Directory.CreateDirectory("CurCut\\"); //List<string> initlist = new List<string>(); SavePos zz = new SavePos(0); //Savesettings.Add(textBox10.Text); //initlist.Add("0"); SaveSetting(zz); return(false); } }
public static void mouse_click_fast(Double[,] imgintsum, int[,] colors, SavePos poss) { Point curpoint = new Point(0, 0); System.Threading.Thread.Sleep(2000); int x_max = imgintsum.GetLength(0); int y_max = imgintsum.GetLength(1); int resolution_pixel = 2; Double curcolor = 0; Double corxnearcolor = 0; Double corynearcolor = 0; Double xdiffer = 0; Double ydiffer = 0; int pixel_differ = 255; int pixel_differ_low = 85; int counter = 0; GetCursorPos(out curpoint); Point Initpoint = curpoint; ////首先画轮廓 /////移到黑色 SetCursorPos(Convert.ToInt32(poss.Black_x), Convert.ToInt32(poss.Black_y)); System.Threading.Thread.Sleep(40); mouse_event(0x0002, 0, 0, 1, 0); //System.Threading.Thread.Sleep(20); mouse_event(0x0004, 0, 0, 1, 0); while (counter < 10000) { //回到初始点 SetCursorPos(Initpoint.X, Initpoint.Y); for (int i = 0; i < x_max; i++) { for (int j = 0; j < y_max; j++) { GetCursorPos(out curpoint); SetCursorPos(curpoint.X + resolution_pixel, curpoint.Y); curcolor = imgintsum[j, i]; if (j > 0 && i > 0) { corxnearcolor = imgintsum[j - 1, i]; corynearcolor = imgintsum[j, i - 1]; xdiffer = Math.Abs(curcolor - corxnearcolor); ydiffer = Math.Abs(curcolor - corynearcolor); } else { xdiffer = 0; ydiffer = 0; } //intdiffer > 35 && curcolor<40 if ((pixel_differ_low < xdiffer && xdiffer <= pixel_differ) || (pixel_differ_low < ydiffer && ydiffer <= pixel_differ)) { mouse_event(0x0002, 0, 0, 1, 0); //System.Threading.Thread.Sleep(20); mouse_event(0x0004, 0, 0, 1, 0); counter++; GetCursorPos(out curpoint); if (curpoint.X < (Initpoint.X - 10) || curpoint.Y < (Initpoint.Y - 10)) { return; } } if (counter > 10000) { break; } else if (counter == 3000) { System.Threading.Thread.Sleep(2000); counter++; } } if (counter > 10000) { break; } GetCursorPos(out curpoint); SetCursorPos(curpoint.X - x_max * resolution_pixel, curpoint.Y + resolution_pixel); } pixel_differ = pixel_differ_low; pixel_differ_low -= 5; if (pixel_differ_low <= 0) { return; } } int curprintcolor = 0; for (int k = 1; k < 5; k++) { //移动到对应颜色取色 if (k == 1) { SetCursorPos(Convert.ToInt32(poss.Red_x), Convert.ToInt32(poss.Red_y)); System.Threading.Thread.Sleep(40); //poss.Red_x } else if (k == 2) { SetCursorPos(Convert.ToInt32(poss.Green_x), Convert.ToInt32(poss.Green_y)); System.Threading.Thread.Sleep(40); } else if (k == 3) { SetCursorPos(Convert.ToInt32(poss.Blue_x), Convert.ToInt32(poss.Blue_y)); System.Threading.Thread.Sleep(40); } else if (k == 4) { SetCursorPos(Convert.ToInt32(poss.Yellow_x), Convert.ToInt32(poss.Yellow_y)); System.Threading.Thread.Sleep(40); } mouse_event(0x0002, 0, 0, 1, 0); //System.Threading.Thread.Sleep(20); mouse_event(0x0004, 0, 0, 1, 0); //回到初始点 SetCursorPos(Initpoint.X, Initpoint.Y); curprintcolor = k; //开始涂色逻辑 for (int i = 0; i < x_max; i++) { for (int j = 0; j < y_max; j++) { GetCursorPos(out curpoint); SetCursorPos(curpoint.X + resolution_pixel, curpoint.Y); curcolor = colors[j, i]; //intdiffer > 35 && curcolor<40 if (curcolor == curprintcolor) { mouse_event(0x0002, 0, 0, 1, 0); //System.Threading.Thread.Sleep(20); mouse_event(0x0004, 0, 0, 1, 0); counter++; GetCursorPos(out curpoint); if (curpoint.X < (Initpoint.X - 10) || curpoint.Y < (Initpoint.Y - 10)) { return; } } if (counter > 10000) { break; } } if (counter > 10000) { break; } GetCursorPos(out curpoint); SetCursorPos(curpoint.X - x_max * resolution_pixel, curpoint.Y + resolution_pixel); } } counter++; }