private void RequestImageTransform() { if (_image != null && !backgroundWorker.IsBusy) { WorkerData workerData; IPixelTransform transform; IErrorDiffusion ditherer; Bitmap image; statusToolStripStatusLabel.Text = "Running image transform..."; Cursor.Current = Cursors.WaitCursor; this.UseWaitCursor = true; transform = this.GetPixelTransform(); ditherer = this.GetDitheringInstance(); image = _image.Copy(); workerData = new WorkerData { Image = image, Transform = transform, Dither = ditherer, ColorCount = this.GetMaximumColorCount() }; #if USEWORKER backgroundWorker.RunWorkerAsync(workerData); #else backgroundWorker_RunWorkerCompleted(backgroundWorker, new RunWorkerCompletedEventArgs(this.GetTransformedImage(workerData), null, false)); #endif } }
private Bitmap GetTransformedImage(WorkerData workerData) { Bitmap image; Bitmap result; ArgbColor[] pixelData; Size size; IPixelTransform transform; IErrorDiffusion dither; transform = workerData.Transform; dither = workerData.Dither; image = workerData.Image; size = image.Size; pixelData = image.GetPixelsFrom32BitArgbImage(); if (dither != null && dither.Prescan) { // perform the dithering on the source data before // it is transformed this.ProcessPixels(pixelData, size, null, dither); dither = null; } // scan each pixel, apply a transform the pixel // and then dither it this.ProcessPixels(pixelData, size, transform, dither); // create the final bitmap result = pixelData.ToBitmap(size); return(result); }