Как исправить управление, используемое другим процессом
Привет, я хочу сделать программу read image form pc и сделать несколько процессов одновременно проблема заключается в том, что " растровое изображение используется другим процессом.
Пожалуйста помочь ...
Это мой код.:
Что я уже пробовал:
public partial class Form1 : Form { Bitmap OriginalImage; public int pi_depth; public Form1() { InitializeComponent(); } private void pictureBox1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() == DialogResult.OK) { OriginalImage = new Bitmap(ofd.FileName); this.pictureBox1.Image = OriginalImage; } } public double DEPTH_PIXEL(int x1, int y1, int x2, int y2,Bitmap bmp) { double depthcalc = 0; for (int y = y1; y < y2; y++) { for (int x = x1; x < x2; x++) { depthcalc = depthcalc + bmp.GetPixel(x, y).R; } } //pi_depth = (max - pi_depth) / 255; //black bmp.Dispose(); return depthcalc; } private void CMD_PARALLEL_Click(object sender, EventArgs e) { parallelfun(OriginalImage); } public void parallelfun(Bitmap bmpin) { int[] nums = { 1, 2, 3, 4 }; int[] VALX1 = { 000, 201, 301, 401 }; int[] VALY1 = { 000, 201, 301, 401 }; int[] VALX2 = { 200, 300, 400, 500 }; int[] VALY2 = { 200, 300, 400, 500 }; Parallel.ForEach(nums, new ParallelOptions() { MaxDegreeOfParallelism = 5 }, item => { double DEPTH = DEPTH_PIXEL(VALX1[item - 1], VALY1[item - 1], VALX2[item - 1], VALY2[item - 1], bmpin); Result(DEPTH.ToString()); }); } public void Result(string result) { if (listBox1.InvokeRequired) listBox1.Invoke((MethodInvoker)delegate() { listBox1.Items.Add(result); }); else listBox1.Items.Add(result); } }
Gerry Schmitz
БМП.Распоряжаться();
Member 12321673
Извините но это не помогло я попробовал это сделать