public override Bitmap processImage(Bitmap sourceImage, BackgroundWorker worker) { GrayScaleFilter gsf = new GrayScaleFilter(); Bitmap grayIMG = gsf.processImage(sourceImage, worker); Bitmap resultImage = new Bitmap(sourceImage); for (int x = 0; x < sourceImage.Width; x++) { worker.ReportProgress((int)((float)x / resultImage.Width * 100)); if (worker.CancellationPending) { return(null); } for (int y = 0; y < sourceImage.Height; y++) { int sortSize = (coreRad * 2 + 1) * (coreRad * 2 + 1); sortData[] sMas = new sortData[sortSize]; for (int i = 0; i < sortSize; i++) { sMas[i] = new sortData(); } for (int i = -coreRad; i <= coreRad; i++) { for (int j = -coreRad; j <= coreRad; j++) { int idX = Clamp(x + i, 0, sourceImage.Width - 1); int idY = Clamp(y + j, 0, sourceImage.Height - 1); Color sortColor = grayIMG.GetPixel(idX, idY); int index = (i + coreRad) * (coreRad * 2 + 1) + (j + coreRad); sMas[index].value = sortColor.R; sMas[index].posX = idX; sMas[index].posY = idY; } } sortMas(sMas, sortSize); int posX = sMas[sortSize / 2].posX; int posY = sMas[sortSize / 2].posY; resultImage.SetPixel(x, y, sourceImage.GetPixel(posX, posY)); } } return(resultImage); }
private void вПолутоновоеToolStripMenuItem_Click(object sender, EventArgs e) { Filters filter = new GrayScaleFilter(); backgroundWorker1.RunWorkerAsync(filter); }