public override Bitmap proccessImage(Bitmap sourceImage, BackgroundWorker worker) { GrayScaleFilter gray = new GrayScaleFilter(); Bitmap sourceImage1 = gray.proccessImage(sourceImage, worker); bool[,] binaryImage = new bool[sourceImage.Width, sourceImage.Height]; Bitmap resultImage = new Bitmap(sourceImage1); for (int i = 0; i < sourceImage.Width; ++i) { worker.ReportProgress((int)((float)i / resultImage.Width * 50)); if (worker.CancellationPending) { return(null); } for (int j = 0; j < sourceImage.Height; ++j) { binaryImage[i, j] = makeBinary(sourceImage1, i, j); } } int height = structureElement.GetLength(0) / 2; int width = structureElement.GetLength(1) / 2; for (int i = width; i < sourceImage.Width - width; ++i) { worker.ReportProgress((int)((float)(resultImage.Width + i) / resultImage.Width * 50)); if (worker.CancellationPending) { return(null); } for (int j = height; j < sourceImage.Height - height; ++j) { bool pos = calculateNewPos(binaryImage, i, j); if (pos) { resultImage.SetPixel(i, j, Color.Black); } else { resultImage.SetPixel(i, j, Color.White); } } } return(resultImage); }
public override Bitmap proccessImage(Bitmap sourceImage, BackgroundWorker worker) { Bitmap resultImage = new Bitmap(sourceImage.Width, sourceImage.Height); GrayScaleFilter gray = new GrayScaleFilter(); Bitmap newSourceImage = gray.proccessImage(sourceImage, worker); for (int i = 0; i < newSourceImage.Width; ++i) { worker.ReportProgress((int)((float)i / resultImage.Width * 100)); if (worker.CancellationPending) { return(null); } for (int j = 0; j < newSourceImage.Height; ++j) { resultImage.SetPixel(i, j, calculateNewPixelColor(newSourceImage, i, j)); } } return(resultImage); }