private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data == null) { return; } Debug.WriteLine(e.Data); string data = e.Data.ToString(); if (data.Substring(0, 1) == "[") { data = data.Replace(" ", " ").Replace(".", "").Replace("[ ", "").Replace("[", "").Replace(" ]", "").Replace("]", ""); var numbers = data.Split(' '); int[] arr = Array.ConvertAll(numbers, s => int.Parse(s)); for (int i = 0; i < arr.Length; i++) { arr[i] = (arr[i] == -1) ? 0 : 255; } byte[] arrByte = Array.ConvertAll(arr, s => (byte)s); var arr2d = Make2DArray(arrByte, x, y); TypeConverter tc = TypeDescriptor.GetConverter(typeof(Bitmap)); Bitmap bm = new Bitmap(x * 100, y * 100); using (Graphics g = Graphics.FromImage(bm)) { for (int i = 0; i < arr2d.GetLength(0); i++) { for (int j = 0; j < arr2d.GetLength(1); j++) { if (arr2d[i, j] == 255) { g.FillRectangle(Brushes.Black, i * 10, j * 10, 10, 10); } else { g.FillRectangle(Brushes.White, i * 10, j * 10, 10, 10); } } } } if (pythonStatus == 0) { OriginalPictureBox.Invoke((MethodInvoker)(() => { OriginalPictureBox.Image = bm; } )); pythonStatus = 1; } else if (pythonStatus == 1) { MainPictureBox.Invoke((MethodInvoker)(() => { MainPictureBox.Image = bm; } )); } } }
private void LoadOriginal() { OriginalImage = Image.FromFile(OriginalFilePath); OriginalPictureBox.Invoke((MethodInvoker) delegate() { OriginalPictureBox.Image = OriginalImage; }); SplitImageButton.Invoke((MethodInvoker) delegate() { SplitImageButton.Enabled = true; }); }